Hi all, I'm having a problem with a PHP webstat code. I don't have any sql access, so I'm using one that writes to a flat file. Here is the code:
<?php
session_start();
if(!session_is_registered('counted')){
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$date = date("l dS of F Y h:i:s A");
$entry_line = "$date - IP: $ip | Agent: $agent | URL: $uri | Referrer: $ref";
$fp = fopen("logs.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
session_register('counted');
}
?>
Since I'm not advanced enough to do a hole php page, I figured I'd just save the above as stat.php and use an include in the .phtml document.
I've tried putting it in the head and body of the document, but I always get the same error:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/freehost/t35.com/c/h/chozen/site/home.phtml:4) in /home/freehost/t35.com/c/h/chozen/site/stat.php on line 2
Any idea whats wrong? Judging by the error, I figure I have to stop the headers from being sent before the code is executed, but how?
Any and all help would be greatly appreciated. 🙂