Php代码似乎运行了两次

时间:2012-02-22 19:00:08

标签: 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);


?>

1 个答案:

答案 0 :(得分:2)

我认为这可能是因为对favicon.ico的要求。浏览器向http://your-site.com/favicon.ico请求,网站服务器将此请求重写为脚本,将其记录到文件中。所以你在日志文件中得到两行。