Expire a hash in a database

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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Expire a hash in a database

Post by Luke »

I am making a site where you pay for a packet of information, and once you sign up, it puts a hash of the following string:

$timestamp.$orderID.$customerip

I then store that information in the database, and when the customer wants to download the packet, they just have to follow a link with that hash appended to the url, I will have the page check that it is a valid hash, and then let them download the file. I want the hash that is in their database to expire after 24 hours or so... is there a way that you can change the hash stored in the database after 24 hours?

Also... how would I make it so that the file can't be downloaded by people other than the ones with valid hashes? Is there a way to protect files from being downloaded?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Store a timestamp with each record. To protect files place them in a non-web dir and read them out using php, and use header() to force a download.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Alright... I got the time thing working... It just checks to see if 86400 seconds have elapsed. But the second part I don't know how to do.. what kind of features does php have that I can read the file with? fopen?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply