任何人都可以幫助下面的代碼運行,並能正常工作,但似乎總是每次記錄一個單一的提示一個單一的提示。Php代碼似乎運行兩次
不知道它的主機或我的代碼
Time: 23rd February 2012 5:45:36 am
IP Address: xxx.xxx.141.162
Browser: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1Time: 23rd February 2012 5:45:36 am
IP Address: xxx.xxx.141.162
Browser: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
。
<?php
// Create a new image instance
$im = imagecreatetruecolor(60, 20);
// Make the background red
imagefilledrectangle($im, 0, 0, 60, 20, 0xFF0000);
// Draw a text string on the image
imagestring($im, 3, 1, 1, 'Tracking', 0xCCFFFF);
// Output the image to browser
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
// Get server variables
$address = $_SERVER['REMOTE_ADDR'];
$referer = isset($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : '';
$browser = $_SERVER['HTTP_USER_AGENT'];
//Open log file
$file = fopen("log.html",'a');
//Set time zone and date format
date_default_timezone_set('Australia/Sydney');
$accessTime = date("jS F Y g:i:s a");
//write collected data to file
fwrite($file, "<b>Time:</b> $accessTime<br />");
if($address != null)
fwrite($file,"<b>IP Address:</b> $address<br />");
if($referer != null)
fwrite($file,"<b>Referer:<b> $referer<br />");
fwrite($file,"<b>Browser:</b> $browser<hr>");
// save file and close
fclose($file);
?>
這不是導致它的代碼。檢查您的主機帳戶上可能有的任何重寫規則。 – 2012-02-22 19:01:57
一個數據庫是一個更好的方式來做記錄。如果您運行的Apache默認情況下由服務器記錄。 – 2012-02-22 19:03:38
日誌的樣本是否正確?每個「時間」行都有*兩個*後面的「IP」/「瀏覽器」行?這是您的實際代碼,還是已被修改? – Kitsune 2012-02-22 19:08:28