Can someone please help me out and explain to me why my script will not create the desired file I want. The paths are correct so it is not them.
<?php
error_reporting(E_ALL);
/* Count number of hits on the site when user enters site
* for the first time every three hours
*/
function countPageHits() {
$date = date('m_d_Y');
$ip = $_SERVER['REMOTE_ADDR'];
$path = '../logs/counter/CounterLog.'.$date.'.log';
if(!isset($_COOKIE['COUNT'])) {
if(!is_file($path))
createNewLog($path);
$handle = fopen($path, 'a');
$contents = $ip.' '.time().' '.$_SERVER['REQUEST_URI'];
fwrite($handle, $contents);
fclose($handle);
setcookie('COUNT', 'counted', time()+60*60*3, '/');
}
}
/* Create new log is it does not exists */
function createNewLog($path) {
if(!is_file($path)) {
if(!$handle = fopen($path, 'w')) {
echo "Cannot create file";
exit;
}
fclose($handle);
}
}
countPageHits();
?>