Also, here's a piece of code (kind of sloppy, but does the trick) I use in a set of scripts that logs hits to a site that uses file I/O to create and write to the log file. You can use it as a reference.
$useragent = $HTTP_USER_AGENT;
$page = $REQUEST_URI;
$ip = $REMOTE_ADDR;
$date = date("l, F jS, g:i:s a");
$logfile = "phplog/log.txt";
## Open logfile. Create it if it doesn't exist
$fp = fopen ("$logfile", "a");
$line_count = file("$logfile");
$line_count = count($line_count);
if (filesize($logfile) == 0) {
$line_id = 1;
}
else{
$line_id = $line_count +1;
}
if ($page == "/") { $page = "root"; }
## Insert data into log file
fputs ($fp, "$line_id||$date||$page||$ip||$useragent||$HTTP_REFERER\n");
fclose($fp);