Howto create a little php script that logs the referer on your page
From How2s
(Redirected from How to create a little php script that logs the referer on your page)
If you want to have a little log file that tracks who is accessing your site at what time with which ip, user agent and from which site (e.g. google search queries or links from other sites), I recommend the following little function:
/**
* @author christoph burgdorfer emc at postbox dot ch
* @date 16.04.2006
* @param string $logfile path to logfile
* @return boolean true or false depending on success
*
*/
function write_log($logfile = "./log/log.txt") {
$fh = fopen($logfile, "a+b");
$content = '"' . date("H:i:s m.d.y", mktime()) . "\";\""
. $_SERVER["REMOTE_ADDR"] ."\";\""
. $_SERVER["HTTP_REFERER"] . "\";\""
. $_SERVER["HTTP_USER_AGENT"]
. "\"\n";
if (fwrite($fh, $content) === FALSE) {
return false;
}
fclose($fh);
return true;
}
This assumes, that the logs are being written into ./log/log.txt which has the appropriate rights/privileges.

