douqian6315 2012-02-22 19:00
浏览 94

Php代码似乎运行了两次

Can any any one help with the following code it runs and works fine but seems to always log a double entry each time for a single hint.

Not sure if its the host or my code

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条回答 默认 最新

  • dst67283 2012-02-22 19:11
    关注

    I think this may be because of request to favicon.ico. Browser does request to http://your-site.com/favicon.ico and webserver rewrite this request to your script that log it to file. So you get two lines in log file.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)