Hi
This is day two of php for me. My head hurts. I have a script that takes names, scores,minutes taken,and seconds taken by each player from a Flash game, sorts them into order by score and returns the records to the game and it actually works!
However I now wish to remove records that are over 7 days old and would be grateful for tips on the easiest way to do it.
The code I have is
$winscore = (int)$winscore;
$keeptime = 7*(24*60*60);
$scoretime= time();
// Create a Blank File if it doesn't already exist
if (!file_exists($x4high.sco))
{
$file=fopen($x4high.sco, "w");
fclose ($file);
}
// Read the file in
$oscores = file ($x4high.sco);
$numreadin = count($oscores);
// Break out the data into a new 2-d array called $tscores
for ($i = 0; $i < $numreadin; $i++)
{
$g = unserialize($oscores[$i]);
$tscores[$i][0] = $g[0];
$tscores[$i][1] = $g[1];
$tscores[$i][2] = $g[2];
$tscores[$i][3] = $g[3];
}
// Fill in any missing data with none/0
for ($i = $numreadin; $i < $scoresize; $i++)
{
$tscores[$i][0] = 0;
$tscores[$i][1] = "none";
}
// Process the actions
// Insert a score/name
if ($action == "INSERT")
{
// Add name to end of list, and sort
$tscores[$scoresize + 1][0] = $winscore;
$tscores[$scoresize + 1][1] = $winname;
$tscores[$scoresize + 1][2] = $winmins;
$tscores[$scoresize + 1][3] = $winsecs;
sort ($tscores);
$file=fopen($x4high.sco, "w");
// Write them out
for ($i = 0; $i < $scoresize; $i++)
/
{
$st = serialize($tscores[$i]) . "\n";
fputs($file, $st);}
fclose($file);
}
I can't figure out how to add a new field with a timestamp for each record. I then need to delete those records where the (current time-timestamp)>keeptime. This is defeating me.
Any tips would be much appreciated.