php script address in image tag messes up the $HTTP_REFERER

General discussions related to php

Moderators: macek, egami, gesf

Tony121076
New php-forum User
New php-forum User
Posts: 28
Joined: Fri Jan 03, 2003 4:00 pm

php script address in image tag messes up the $HTTP_REFERER

Postby Tony121076 » Wed Feb 12, 2003 3:31 pm

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.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Feb 13, 2003 10:53 pm

script must locate at same server that site =)

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Feb 13, 2003 10:56 pm

part of the php script counter

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


Code: Select all

$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;

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Fri Feb 14, 2003 8:01 am

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'];


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 4 guests