make a download expire?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

make a download expire?

Post by ecaandrew »

hello i need help with making a download expire, itll be a product being purchased through paypal ipn, and it will be downloaded a lot, i need the download to expire, right now what i have is a field in my downloads table called "hex" which is the md5("FILEURL"), and when they purchase the download they get an email going to download.php?38724187328947328dfshafjkhsafdsa(hex code) and that redirects to the file download, but i need it so the file expires for each person who downloads it, paypal automitcally generates a unique ID called TXN_ID, i was figuring i can use that somehow, but if someone can help me think of how to do it, thatd be awesome, thanks, i need it to expire in 48 hours somehow.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Insert a timestamp in your database which is updated with the current timestamp of the time purchased. then run a check everytime a user laods the page for expired times... ( if timestamp > timestamp+48hours )

then update the field again which will flag it expired..
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

i get it but i dont
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Question

Post by thomas777neo »

So, on download, you want the file to delete itself after a specific period of time. Like a cookie?
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

no, its to be able to be downloaded by multiple people buying the product, so like they will be emailed

http://blah.com/download.php?HEXCODEHER ... 3721094321



each person who buys the template is given a unique TXN ID, so i figure i can tmake it expire with that some how, i dunno....
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

like maybe i can have the TXN ID entered in the Database, and have it expire according to TXN ID? but how so
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Agreement

Post by thomas777neo »

Then I agree with Phenom's idea.

Maybe he can give you a sample of code
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

maybe someone can help me let me show you what i think, but i know it wont work


when paypal process is finished

INSTERT the TXN_ID into table_downloads

mail the user
http://blah.com/download.php?hex=md5(FI ... TXNID_HERE

once they get to that page


download.php FILE
-------------------------------------------------------------------------

Code: Select all

<?php	
DBCONNECT HERE

$GRABTXNID = @mysql_query("SELECT * FROM `orders` WHERE `txn_id` = '" . $_GET['txnid'] . "'");

--- SOME ACTION HERE I CANNOT THING OF,  ---

$GRABDOWNLOADURL= @mysql_query("SELECT * FROM `templates` WHERE `hex` = '" . $_GET['file'] . "'");
$row = @mysql_fetch_array($GRABDOWNLOADURL);

header("location: " . $row['file']);


?>
Last edited by ecaandrew on Mon Nov 15, 2004 5:47 am, edited 1 time in total.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

insert another field that has a ie. (purchasedDate)datestamp in it that gets set/updated when someone purchases the file.
When they click on the email link do a quick check to make sure that say 48 hours hasn't passed first.

If it hasn't then let them down load the file using your current system other wise tell them that the download has expired.
see

[mysql_man]datediff[/mysql_man] in the manual
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

what kind of timestamp should i use to enter the date????

$purchastedate = timestamp();

??? something like that, thanks
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

anyone?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

check out http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html from the mysql man, it should get you in the right direction as well as examples of how to do what you want to do.
Post Reply