inserting unique date into txt document
- by durian
I'm trying this script to insert only a unique date into a text file, but it isn't working properly:
$log_file_name = "logfile.txt";
$log_file_path = "log_files/$id/$log_file_name";
if(file_exists($log_file_path)){
$not = "not";
$todaydate = date('d,m,Y');
$today = "$todaydate;";
$strlength = strlen($today);
$file_contents = file_get_contents($log_file_path);
$file_contents_arry = explode(";",$file_contents);
if(!in_array($todaytodaydate,$file_contents_arry)){
$append = fopen($log_file_path, 'a');
$write = fwrite($append,$today); //writes our string to our file.
$close = fclose($append); //closes our file
}
else {
$append = fopen($log_file_path, 'a');
$write = fwrite($append,$not); //writes our string to our file.
$close = fclose($append); //closes our file
}
}
else{
mkdir("log_files/$id", 0700);
$todaydate = date('d,m,Y');
$today = "$todaydate;";
$strlength = strlen($today);
$create = fopen($log_file_path, "w");
$write = fwrite($create, $today, $strlength); //writes our string to our file.
$close = fclose($create); //closes our file
}
The problem is with the if else statement where it should be written if it's already in the array.