,同时windows换行符是"rn",linux换行符是"n"
PHP记录IP的函数是 $_SERVER["REMOTE_ADDR"]
PHP获取当前时间函数date("Y-m-d H:i:s", time())
PHP获取来路网址函数$_SERVER['HTTP_REFERER'] 首先要判断其是否为空值,即用isset进行判断,比如我们直接从浏览器敲入网址则不会有来路网址记录,最后代码很简单,如下:
代码如下 |
复制代码 |
$ip = $_SERVER["REMOTE_ADDR"];
$time = date("Y-m-d H:i:s", time());
$from = '';
if(isset($_SERVER['HTTP_REFERER']))
{
$from = $_SERVER['HTTP_REFERER'];
}
$myfile = 'wtndata/statistic.txt';
$str = "ip='".$ip."' from='".$from."' time='".$time."'rn";
$file_pointer = fopen($myfile,"a");
fwrite($file_pointer,$str);
fclose($file_pointer);
|