Anis Rétro
Anis Rétro

Reputation: 93

cannot get http headers in local network

I'm doing a pixel tracking but when I try to get the HTTP Headers using cURL, it returns this:

Output

the current code:

<?php
  $img = imagecreate(1,1);
  $white = imagecolorallocate($img, 255, 255, 255);
  imagesetpixel($img,1,1,$white);
  header("content-type: image/jpg");
  imagejpeg($img);
  imagedestroy($img);
  $file = fopen("results.txt", "a");
  $ip = $_SERVER['REMOTE_ADDR'];
  $date = date("r");
  fwrite($file, "$ip from: $_SERVER['HTTP_REFERER'] at $date");
  fclose($file);
?>

Upvotes: 0

Views: 51

Answers (1)

Haresh Vidja
Haresh Vidja

Reputation: 8496

  1. First of all add line i records.txt
  2. Generate Image
  3. Do ob_clean(), it will remove output if warning occures
  4. Give output of image
  5. do not close php tag.
  6. try it with browser instead of CURL because curl output should be garbase collection because output is in binary format.

PHP:

<?php

  $file = fopen("results.txt", "a");
  $ip = $_SERVER['REMOTE_ADDR'];
  $date = date("r");
  fwrite($file, "$ip from: $_SERVER['HTTP_REFERER'] at $date");
  fclose($file);
  $img = imagecreate(1,1);
  $white = imagecolorallocate($img, 255, 255, 255);
  imagesetpixel($img,1,1,$white);
  header("content-type: image/jpg");
  ob_clean();
  imagejpeg($img);
  imagedestroy($img);

Upvotes: 1

Related Questions