好的,所以基本上脚本可以工作,但是每次我刷新 data.txt 文件时都会被覆盖,我希望它将每个单独的条目添加到新文件中的 data.txt 中。
示例:1.1.1.1 7 月 18 日 @ 下午 2:03:17
<?php
date_default_timezone_set("Europe/London");
function GetAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$adresseip = GetAddr();
function sec2hms($sec, $padHours = false) {
@$hms = "";
@$days = intval($sec/86400);
if($days > 0 ) {
if($days == 1) {
@$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$days.' Day');
} else {
@$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$days.' Days');
}
}
@$sec-= ($days*86400);
@$hours = intval(intval($sec) / 3600);
if($hours > 0) {
if($days > 0) { @$s = ', '; }
if($hours == 1) {
@$hms .= @$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$hours.' Hour');
} else {
@$hms .= @$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$hours.' Hours');
}
}
@$minutes = intval(($sec / 60) % 60);
if($minutes > 0) {
if($hours > 0) { @$d = ', '; }
if($minutes == 1) {
@$hms .= @$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minute';
} else {
@$hms .= @$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minutes';
}
}
@$seconds = intval($sec % 60);
if($seconds > 0) {
if($minutes > 0) { @$p = ', '; }
if($seconds == 1) {
@$hms .= @$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Second';
} else {
@$hms .= @$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Seconds';
}
}
return @$hms;
}
function report($data) {
$time = date('g:i:s A', time());
echo "[$time] $data\n";
}
$d= date('F jS @ g:i:s a');
$fp = fopen('data.txt', 'r+');
fwrite($fp,"$adresseip - $d");
fclose($fp);
?>