<?php
error_reporting(E_ALL);
// Getting the information
$ipaddress = $_SERVER['REMOTE_ADDR'];
$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
if(!empty($_SERVER['QUERY_STRING']) $page .= $_SERVER['QUERY_STRING'];
$referrer = $_SERVER['HTTP_REFERER'];
$datetime = mktime();
$useragent = $_SERVER['HTTP_USER_AGENT'];
$remotehost = getHostByAddr($ipaddress);
// Create log line
$logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . "\n";
echo $logline;
// Write to log file:
//$logfile = 'logfile.txt';
$logfile = '/home/www/agro-dive.onlinewebshop.net/logfile.txt';
// Open the log file in "Append" mode
if (!$handle = fopen($logfile, 'a+')) {
die("Failed to open log file");
}
// Write $logline to our logfile.
if (fwrite($handle, $logline) == FALSE) {
die("Failed to write to log file");
}
fclose($handle);
?>
如果我尝试打开这个 php,它会给我一个服务器错误
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
我也按照此处的步骤对其进行了测试,但它没有产生任何日志消息