Page 1 of 1

Can't get the HTTP_REF.. to work

Posted: Wed Jan 08, 2003 5:14 am
by conthox
Hello

I want to check the URL that people came from, but I can't make it work! :(

What is the code I have to write?

Thanks for helping me!

Posted: Wed Jan 08, 2003 5:33 am
by twigletmac
First of all you should read this from the manual:
'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
Aside from this issue you should use:

Code: Select all

$_SERVER['HTTP_REFERER']
to access this infomation (if available) for PHP version 4.1 and up or if you are using PHP version 4.0.6 or below:

Code: Select all

$HTTP_SERVER_VARS['HTTP_REFERER']
Mac

Posted: Wed Jan 08, 2003 5:36 am
by Elmseeker
Try:

Code: Select all

$ref = $HTTP_SERVER_VARS["HTTP_REFERER"];
echo "Thank you, you were sent to this page by ".$ref."!";
[Edit]

Heh, Sorry Twig...we must have been editing at same time lol.

Posted: Wed Jan 08, 2003 5:38 am
by twigletmac
For PHP 4.1 or above (if you don't have the need to be compatible with older versions of PHP) it's better to use:

Code: Select all

$ref = $_SERVER['HTTP_REFERER'];
instead of

Code: Select all

$ref = $HTTP_SERVER_VARS['HTTP_REFERER'];
It cuts the typing down :) .

Mac

Posted: Wed Jan 08, 2003 5:41 am
by Elmseeker
True, anything that works the same way and saves keystrokes is a GOOD thing! I just upgraded to a newer than 4.1 version of PHP and REALLY need to get used to the shorter names of the super globals hehe...

Posted: Wed Jan 08, 2003 5:48 am
by conthox
Thank you!

I really appreciate your help.