0

我正在研究一个跟踪像素,它应该将请求者的 ip 和一些其他信息记录到一个 html 文件中,但是 html 文件永远不会被创建,如果我创建它,它就会保持为空。

<?php

  // Create an image, 1x1 pixel in size
  $im=imagecreate(1,1);

  // Set the background colour
  $white=imagecolorallocate($im,255,255,255);

  // Allocate the background colour
  imagesetpixel($im,1,1,$white);

  // Set the image type
  header("content-type:image/jpg");

  // Create a JPEG file from the image
  imagejpeg($im);

  // Free memory associated with the image
  imagedestroy($im);

  // Server variables
  $ip = $_SERVER['REMOTE_ADDR'];
  $referer = $_SERVER['HTTP_REFERER'];
  $useragent = $_SERVER['HTTP_USER_AGENT'];
  $browser = get_browser(null, true);
  $fecha = date("Y-m-d;h:i:s");
  if (isset($_GET['type'])) {
    $type = $_GET['type'];
  }
  $f = fopen("list.html", "a");

  fwrite ($f,
  'IP: [<b><font color="#660000">'.$ip.'</font></b>]
  Referer: [<b><font color="#9900FF">'.$referer.'</font></b>]
  User Agent: [<b><font color="#996600">'.$useragent.'</font></b>]
  Browser: [<b><font color="#996600">'.$browser.'</font></b>]
  Date: [<b><font color="#FF6633">'.$fecha.'</font></b>]<br> ');
  if (isset($type) {
    fwrite ($f, 'Type: [<b><font color="#660000">'.$type.'</font></b>]'
  fclose($f);
?>
4

1 回答 1

0

您的脚本末尾有错误,它必须是:

if ( isset($type) ) {
  fwrite ($f, 'Type: [<b><font color="#660000">'.$type.'</font></b>]');
  fclose($f);
}
?>

更正了它,你的脚本有效

于 2016-12-02T18:07:06.743 回答