faqts : Computers : Programming : Languages : PHP : Function Libraries : URL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 20 people (85%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Is there a way to capture the URL from the page a visitor has come from?

Jan 25th, 2001 21:14
Philip Olson, mark romero,


Yes!  Using the predefined variable HTTP_REFERER, this can be done.  
Read about predefined variables here :
    http://www.php.net/manual/en/language.variables.predefined.php
Not all browsers provide this information but most do.  A couple ways 
to print out this variable is as such :
    print $HTTP_REFERER;
    print getenv('HTTP_REFERER');
Calling this directly will print nothing, a referrer MUST exist.  Also 
it's worth mentioning that referer is a misspelling but that's just how 
it is, here's some information on that :
    http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=referer
In a sense, a referer is referred ;-)