php script address in image tag messes up the $HTTP_REFERER

A

Anonymous

Guest
I made a hit counter in php. I added an image tag to my home page with the path to my php script in it. It executes the script, but the $HTTP_REFERER variable give the current address instead of the last address. Please help!

How can I call my php script from an html page in a way that the $HTTP_REFERER variable works properly?

Thank you for your time and attention.
 
part of the php script counter

never mind at russian, it was a titorial (my) for ru_php =)


Code:
$COUNT_FILE = "_datadir/$file.dat";

$message="";

// $ip - ýòî òîò ñàìûé àéïèøíèê ;)
$ip = getenv("REMOTE_ADDR")."::".getenv("HTTP_X_FORWARDED_FOR");
// âû÷èñëÿåì äàòó. -3 ÷àñà - ýòî ðàçíèöà ïî âðåìåíè ñ Ìîñêâîé. Ñêðèïò ðàáîòàåò ïî Ìîñêâå
$datum=date("d.m.Y", time());
// îòêðûâàåì ôàéë
$fp = fopen("$COUNT_FILE", "rb");
flock($fp,1);
$contents=fread ($fp, filesize ($COUNT_FILE));
fclose ($fp);
// ñ÷èòûâàåì êîë-âî õèòîâ, óíèêóìîâ è ïð.
$content= explode("\n",$contents);
$counts= explode("|",$content[0]);
$counts[3]=chop($counts[3]);
if ($counts[3]=="") {$counts[3]="1";}
// åñëè ip-øíèê - óíèêàëüíûé (ñåãîäíÿ åãî åùå íå áûëî), òî äîáàâëÿåì â áàçó è +1 ê óíèêóìàì
if (!in_array ($ip, $content)) { $content[] = $ip; $counts[1]++; }
// óâåëè÷åíèå õèòîâ
$counts[2]++;
$counts[3]++;
// ïîëíî÷ü. ;)
if ($counts[0]!=$datum) {
$message="total hits:    ".$counts[3]."\ntoday hits:    ".$counts[2]."\ntoday uniques: ".$counts[1];

$r11=$counts[1];
$r21=$counts[2];
// ñ÷åò÷èê îáíóëÿåòñÿ.
$counts[0]=$datum; $counts[1]=1; $counts[2]=1;
}

// îòîáðàæåíèå
//echo ("<b title=\"Ñ 12.12.2002\" >".$counts[3]."</b>/".$counts[2]."/".$counts[1]);
$dead="$counts[3]/$counts[2]/$counts[1]";
// çàïèñü â ôàéë
$content[0]=$counts[0]."|".$counts[1]."|".$counts[2]."|".$counts[3];
$fd = fopen("$COUNT_FILE", "a");
$locked = flock($fd,2);
if ($locked) {
$fp = fopen("$COUNT_FILE", "wb");
if ($message=="") { fwrite($fp, implode("\n",$content)); }
else  { fwrite($fp,$content[0]);  }
fclose($fp);
}
fclose($fd);
///  Îòïðàâëÿåì âñå ýòî ïî ïî÷òå (ðåçóëüòàòû çà ïðîøëûå ñóòêè)
if ($message!=""):
//mail("mitya@alesh.ru,pejone@mail.ru", "Ñòàòèñòèêà lj.alesh.ru", $message, "From: ljstats@alesh.ru");
endif;
 
any src of an image tag is effectively a new http request from the calling page to the image (or scripts as the case may be) - so calling an img src would always register the http referer as the calling page and not the page that called the calling page.

you could get round it by passing the referer as a get variable to the src script

eg <img src="counter.php?referer=<?=$_SERVER['HTTP_REFERER'];?>" />

and
$the_referer = $_GET['referer'];
 
Back
Top