我似乎无法确定为什么当客户端IP存在时,它不附加到该文件。file_put_contents()不写入文件
我一直运行echo语句直到file_put_contents()
函数,我可以看到变量中的内容。
$file = 'log.txt';
$now = new DateTime();
$timestamp = $now->format('Y-m-d H:i');
if (isset($_SERVER['REMOTE_ADDR'])){
$log = $_SERVER['REMOTE_ADDR'].' '. $timestamp;
}else{
$log = 'SERVER '.$timestamp;
}
$log = strval($log); //convert to string
$log .= "\n\r";
file_put_contents($file,$log,FILE_APPEND);
明显的问题在这里...你有写log.txt权限吗? –
你检查了文件的权限吗? – TimWolla
您应该始终检查'file_put_contents'的返回值以查看它是否返回FALSE。 –