Page 1 of 1
HTTP_REFERER and php 5
Posted: Wed Nov 10, 2004 4:25 pm
by pelegk2
i am working with php 5 and when i try :
Code: Select all
<?=$HTTP_SERVER_VARSї'HTTP_REFERER']?>
i revice :
Undefined index: HTTP_REFERER
why is that
thnaks in advance
peleg
Posted: Wed Nov 10, 2004 4:44 pm
by rehfeld
stop using the $HTTP_*_VARS
they are deprecated since php4
you can still use them but i beleive youll need to set them in your php.ini
use $_POST $_GET $_SERVER $_COOKIE etc.....
http://php.net/language.variables.predefined
the undefined index means that there is no
'HTTP_REFERER' in the $HTTP_SERVER_VARS array
$foo = array('foo' => 'something');
echo $foo['bar']; //undefined index 'bar'
welll
Posted: Wed Nov 10, 2004 4:52 pm
by pelegk2
my mistake i origanlly used : $_SERVER['HTTP_REFERER']
but still te samem istake
what to do?
Posted: Wed Nov 10, 2004 4:58 pm
by rehfeld
variables in the server array arent always guaranteed to be set
if the browser didnt send a referrer header, thats prob why php didnt set it.
all you can really do is check if its set before trying to use it
if (isSet($_SERVER['HTTP_REFERER'])) {
echo $_SERVER['HTTP_REFERER'] ;
}
you could also try
getenv('HTTP_REFERER')
or
$_ENV['HTTP_REFERER'];
but thats likely not to work if the server array doesnt have it either.
Posted: Thu Nov 11, 2004 1:36 am
by pelegk2
the thing is that the referer should come from my server that makes the referer
how can i check why my server doesnt do it?
Posted: Thu Nov 11, 2004 2:41 am
by phpScott
what are you using as a server? It will be different say between apache and IIS and various other servers.
Posted: Thu Nov 11, 2004 2:52 am
by pelegk2
apache 2.0.46 php 4.3.2 on window 2000
Posted: Thu Nov 11, 2004 3:21 am
by rehfeld
browsers do not always send a referrer header. there is absolutely nothing you can do about it.
it doesnt matter where they come from, even your own page, if the browser doesnt want to send it, it wont.
you simply cannot rely upon that variable being available.
but if your saying you cant get it to work after having tried using some diff browsers w/ no luck, then yeah its prob another issue. try using ie, and set its security settings low. it should work.
if your just trying to track user as they browse through your website, sessions and are an easy way, and are very reliable.
Posted: Thu Nov 11, 2004 4:43 am
by pelegk2
the things is that when i made a php program run aon a linux server i got it the REFERER ok!
but when i tried to do the same with php installed on my pc it didnt work
beacuse of that i thought its maybe a php/apache configure problem!
Posted: Thu Nov 11, 2004 6:54 am
by timvw
instead of using the unreliable http_referer..
you could sava "was here" in a session on the intro page...
and on the following pages test if that session still exists

Posted: Thu Nov 11, 2004 7:48 am
by pelegk2
its a prebloem beacuse i want to know for example to which incorrect page (page that dosent exist)
and the apche automaticlly referer it to an error_page.php!!
and in the error page want to know from where ihave came!
how do i do that?thnaks in advance
peleg
Posted: Thu Nov 11, 2004 10:12 am
by timvw
Posted: Thu Nov 11, 2004 4:37 pm
by pelegk2
thnaks alot!