HTTP_REFERER and php 5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

HTTP_REFERER and php 5

Post by pelegk2 »

i am working with php 5 and when i try :

Code: Select all

<?=$HTTP_SERVER_VARS&#1111;'HTTP_REFERER']?>
i revice :
Undefined index: HTTP_REFERER
why is that
thnaks in advance
peleg
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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'
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

welll

Post by pelegk2 »

my mistake i origanlly used : $_SERVER['HTTP_REFERER']
but still te samem istake
what to do?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post 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?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

what are you using as a server? It will be different say between apache and IIS and various other servers.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

apache 2.0.46 php 4.3.2 on window 2000
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post 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!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 ;)
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

thnaks alot!
Post Reply