views:

27

answers:

1

Should I read an image (with php) and then echo it while grabbing the header? Or there is another way?

+1  A: 

You want referrer information of an external image? That should always be whatever your server sends.

However, if you are talking about having an image file on your server that should get referrer information, you could do

 <?php
 // Possibly use mod_rewrite so point your image here

 $referrer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : NULL;
 // Save the referrer somewhere

 header('Content-Type: image/png');

 readfile('image.png');
alex
`readfile()` outputs file itself and returns number of bytes. No `echo` is necessary.
zerkms
@zerkms Thanks, will make an edit.
alex