faqts : Computers : Programming : Languages : PHP : Common Problems

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

117 of 174 people (67%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I get the referer string in PHP?
What is the referer?
How can I find out what site a visitor has come from?

Dec 26th, 2005 03:42
Praveen Kumar Kukkapalli, Nathan Wallace, unknown unknown,


Better to use $_SERVER["HTTP_REFERER"] to know the referer URL.
If the user followed a link to the current page then the referer is the
URL that the user has come to the current page from.  If they typed in
the URL directly or came from their bookmarks then the referer is
generally empty.
PHP makes the referer automatically available in the variable:
    $HTTP_REFERER - the url the client just came from
The referer is actually stored in an environment variable which you can
get using getenv():
    http://www.php.net/manual/function.getenv.php3
To see what information like this is available create a page that
contains just:
    <?php phpinfo() ?>
That will show you all of the environment variables that are available.