gobob Posted August 13, 2007 Share Posted August 13, 2007 I have a normal HTML link on an html page on one site pointing to a test.php file on another site. I want to get the URL of the refering page using PHP, but have so far been unsuccessful. Both $_SERVER['HTTP_REFERER'] and getenv('HTTP_REFERER') provide null results. Also, phpinfo() does not display the HTTP_REFERER. I can successfully get the remote IP addresses with $_SERVER['REMOTE_ADDR']. JavaScript successfully displays the correct refering URL with: <script language=javascript>document.write(referer);</script> so, apparently, the header information is available. I have tried this with MSIE and Firefox browsers. I have also placed the test.php file on two different servers, but in each case PHP failed to find the refering URL. Any suggestions would be helpful. Link to comment https://forums.phpfreaks.com/topic/64711-http_referer-is-null/ Share on other sites More sharing options...
lemmin Posted August 13, 2007 Share Posted August 13, 2007 Have you tried a simple echo $_SERVER['HTTP_REFERER']; ? I think PHP will actually display a warning if you try to use it and it isn't available, so I can only assume it is something in your code. Link to comment https://forums.phpfreaks.com/topic/64711-http_referer-is-null/#findComment-322705 Share on other sites More sharing options...
gobob Posted August 13, 2007 Author Share Posted August 13, 2007 I have tried that. I believe the key is that phpinfo() displays nothing for HTTP_REFERER. In that case I would not expect and PHP variable or function to provide the referer URL. Since I am new at PHP, I have to ask, should PHP display a value for HTTP_REFERER when a .php file is requested by a normal HTML link? Or am I striving in vain for something that normally does not work? Link to comment https://forums.phpfreaks.com/topic/64711-http_referer-is-null/#findComment-322713 Share on other sites More sharing options...
lemmin Posted August 13, 2007 Share Posted August 13, 2007 Does print_r($_SERVER); show anything? This is a guess but, is it possible that the server you are running it on has some kind of redirection that might erase that value? Link to comment https://forums.phpfreaks.com/topic/64711-http_referer-is-null/#findComment-322716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.