Jump to content

how to tell referer with php or javascript like stats websites do?


dsaba

Recommended Posts

Many of you may be familiar with the free statistics websites out there that will let you place a small image on your webpage or a small piece of javascript code that outputs an image..etc.. It will then collect stats about your site..etc..

 

Well, what stumps me is how this javascript or php dynamic image is able to pickup referer information. I've tried making a dynamic php image that spits out referer information, but it will only spit out the last page from where it was loaded which is of course the current page and not the "referer referer" if you know what I'm getting at... 

 

How can I get this referer info with javascript or php dynamic image?

 

Here's an example of a php dynamic image that I can't get around this problem:

3h4f3q

As you can see it tells you that the referer is the page from which is was loaded at which is this very thread. Here's the code I used:

<?php
$ref = trim(@$_SERVER['HTTP_REFERER']);
if (empty($ref)) {
$ref = 'no referer';
}

$im = imagecreatetruecolor(round(strlen($ref)*6.5), 30); 
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagefill($im, 0, 0, $white); //fill image with white
imagecolortransparent($im, $white); //make white color transparent
imagestring($im, 2, 5, 5, $ref, $black); //write string in black color



//display image
header("Content-Type: image/gif");
imagegif($im);
imagedestroy($im);
?>

 

Thanks for looking.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.