I am trying write the day the person logs in in a txt file.
Format: 1 2 3 4 6 8 9
delimieter is a space.
I dont want duplicate entries but my code will continue to add a day even if it already exists.
My Code:
<?
//**Catch variable values from Flash program**//
$filename = $_POST['filename'];
//server date(d) from flash (didnt know how to in PHP at the time)
$day = $_POST['day'];
//**Open/Create current user access log and copy contents to string**//
$file = fopen($_SERVER['DOCUMENT_ROOT'] . "/logs/$filename", "a+");
$currentLogStr = fread($file, filesize($filename));
fclose($file);
//**Check to see if log has entries**//
if ($currentLogStr != ""){
//**If log has entries make array out of data**//
$currentLog = explode(" ",$currentLogStr);
//**Check to see if current day is later than last entry date in $currentLog**//
if ($day > $currentLog[count($currentLog-1)]) //Can I use end($currentLog) here?
{
//**If current day later, add to log**//
$file = fopen($_SERVER['DOCUMENT_ROOT'] . "/logs/$filename", "a+");
fwrite($file,$day . " ");
fclose($file);
}
//**If current day not later than last entry do nothing**//
}else
{
//**If log has no entries add one**//
$file = fopen($_SERVER['DOCUMENT_ROOT'] . "/logs/$filename", "a+");
fwrite($file,$day . " ");
fclose($file);
}
?>
Please help. Ocnce it stops repeating I am done my project (this one anyway)
Thanks,
Pete