View Full Version : php autodelete function
lostreality
13-05-2005, 01:12 AM
anybody know how to set up a PHP autodelete function?
basically what I want to do is have certain info deleted when it reaches its sell-by-date i.e. 7 days.
So you post information on, then instead of having to delete it manually it will just bugger off.
Im trying to not go the myqsl db route and instead use flat filing to store my information.
druid
13-05-2005, 05:08 AM
It would be so much easier with a database but I understand if you can't access one. If you can you should really use it as it makes life so much easier. Setting up MySql is a negligible operation.
Working with files - In this case I believe you need to create some sort of date index for your info. It could be in the name of the file, or just the last modified date depending on what you store. There's too many possibilities and too little info to think further.
The bottom line is that you need something that prunes stuff on a timer, say daily.
Asmodeus
13-05-2005, 05:38 AM
flat files? more problems and work than they're worth.
it'd be much easier for even a total novice to set up a basic db server and a simple cron job that'll flush teh database of old entries daily.
plext
13-05-2005, 07:34 AM
Unlink (http://ie2.php.net/manual/en/function.unlink.php) and filemtime (http://ie2.php.net/manual/en/function.filemtime.php) should be able to get you where you need to go.
AsterisK
13-05-2005, 09:40 AM
stick with database, its not only a fuck load easier, but its probably also better for the system, as you can just select the rows you need and retain historical data, or just make it delete rows older then 7 days. how do you mean auto-delete? is this going to be set up as a cron job, or every time a page loads it checks?
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.