作为我的第一个 PHP 项目之一,我正在创建一个记录用户 IP 地址的 IP 记录脚本。出于某种原因,我的 fwrite() 函数似乎没有写入我的日志文件。
有人可以帮我吗?
<?php
// IP Logger Script
// By Sam Lev
// sam@levnet.us
$iplogfile = 'iplog.txt';
$ipaddress = $_SERVER['REMOTE_ADDR'];
$webpage = $_SERVER['SCRIPT_NAME'];
$timestamp = date('m/d/Y h:i:s');
$browser = $_SERVER['HTTP_USER_AGENT'];
$fp = fopen($iplogfile, 'a+');
chmod($iplogfile, 0777);
fwrite($fp, '['.$timestamp.']: '.$ipaddress.' '.$webpage.' '.$browser. "\r\n");
fclose($fp);
echo "IP ADDRESS: $ipaddress <br />\n";
echo "TIMESTAMP: $timestamp <br />\n";
echo "BROWSER: $browser <br />\n";
echo "Information logged to server. <br />\n";
?>
运行脚本后 iplog.txt 仍为空白。一切都很好。
谢谢