写入PHP中的文件



我正在处理跟踪像素,应该将请求者的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);
?>

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

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

纠正了它,您的脚本工作

最新更新