phphtmlwebtracking-pixel

Writing to file in php


I am working on a tracking pixel, it is supposed to log the ip of the requester and some other info to an html file, but the html file never gets created and if I create it, it stays empty.

<?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);
?>

Solution

  • You have errors at the end of your script, it must be:

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

    corrected it, and your script works