Server variable (Referer) doesn't work

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
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Server variable (Referer) doesn't work

Post by Swede78 »

$HTTP_SERVER_VARS['HTTP_REFERER']

This variable just stopped working for me. It was working before, now it gives me nothing when I try to echo it. I don't think I've changed any settings between the time it worked and now, but I'm not 100% sure of that. Is there anything that would cause this to not work?

Or does anyone know of another way to detect the URL of the last page you came from?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

go to http://www.php.net and checkthe version you're using. it was probably deprecated.

the $HTTP_XXXX_VARS arrays have all been deprecated. for $_XXXX
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Post by Swede78 »

$_SERVER['HTTP_REFERER'] doesn't work either.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

have you tried searching what's there by default via http://www.php.net? how about checking that your test is working rright.. ie: that your bastion host allows refferes to be sent
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Well did you change browsers? The "User-Agent" aka browser is responsible for setting the HTTP_REFERER value. Normally its set when you click a link, so if you/a user reaches the page via a bookmark or via directly typing a url then no HTTP_REFERER will be set. Furthermore some proxies strip HTTP_REFERER information.

Are you testing from a different location than before so maybe there is a different proxy?

ps. the hard part about HTTP_RERERER is knowing when to stop ERERERERERER... :)
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Post by Swede78 »

Nielsene,

That's what it was. I was going to the test URL directly. That makes sense. It was working before and is still working. Some people are getting to the page directly and some people are getting there through a link within my site. Sorry to waste your time.

Thanks,
Swede
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

no problem swede. everyone spaces out at times. it may have been good for you to have spaced out here so that you found out about the deprecation
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

nielsene:
>The "User-Agent" aka browser is responsible for setting the HTTP_REFERER value.
Really??? I thought that came from Apache, since it is an apache enviornment variable!

God help us when we have to depend on browsers for data!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

jmarcv wrote:nielsene:
>The "User-Agent" aka browser is responsible for setting the HTTP_REFERER value.
Really??? I thought that came from Apache, since it is an apache enviornment variable!

God help us when we have to depend on browsers for data!
Definitely comes from the browser - that's why it's so unreliable.

Mac
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

twigletmac wrote:
jmarcv wrote: Definitely comes from the browser - that's why it's so unreliable.

Mac
Yow! So, what other 'Apache Enviornment' variables in PHP are there that don't come from Apache?
Swede78
Forum Contributor
Posts: 198
Joined: Wed Mar 12, 2003 12:52 pm
Location: IL

Post by Swede78 »

Yow! So, what other 'Apache Enviornment' variables in PHP are there that don't come from Apache?
The HTTP_REFERER variable is considered a "Server Variable" (http://us4.php.net/manual/en/reserved.v ... les.server). It's not exclusive to Apache.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

"Server Variables" are just things that PHP expects to have handed to it by the server. In this case Apache/IIS/etc attempts to extract the referrer field from the request and sets it up for php use when handing it over.

So yes, your webserver handles the parsing of the data, but its only as accurate as the value submitted by the user's browser.

This is true of almost all the server variables, the notable exceptions are those that start with "SERVER_*".
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

nielsene

The PHP docs say:
Apache variables
These variables are created by the Apache webserver
.

and it doesn't elaborate.

So, it is very good to know. Thanks.
Post Reply