Yesideez Posted December 7, 2008 Share Posted December 7, 2008 I've got my site redirecting all links to pages to index.php and I'm logging these redirects so I can see where people are linking to. Only problem is, the redirects get logged twice. Once for entering my site from a foreign link and again for my redirection using header(). How can I clear HTTP_REFERER? I've tried apache_setenv() but the function isn't recognised. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/ Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 I think you can do this: $_SERVER['HTTP_REFERER'] = ""; Or you can just add a check and if the referer is from your site, don't log it. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/#findComment-708570 Share on other sites More sharing options...
Yesideez Posted December 7, 2008 Author Share Posted December 7, 2008 Tried it, didn't work The problem is when I redirect to my own site the old HTTP_REFERER variable retains its value instead of being changed to that of mine. Here's my code: function checkReferal($strFile) { $strFrom=$_SERVER['HTTP_REFERER']; if (strpos(strtolower($strFrom),'pictureinthesky')===false&&strlen($strFrom)>3) { mysql_query("INSERT INTO `referrals` (`from`,`ip`,`dt`,`file`) VALUES ('".addslashes($strFrom)."','".getIP()."','".time()."','".$strFile."')"); if ($strFile!='index') { //apache_setenv('HTTP_REFERER',''); //$_SERVER['HTTP_REFERER']=''; //header('Referer: http://www.pictureinthesky.net/'.$strFile.'.php'); header('Location: index.php?re=direct'); exit; } } } The commented lines are what I've tried and proven not to work so far. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/#findComment-708582 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 How about setting a session variable? Then check if that session variable isset, IE: $_SESSION['camefromme'] = true; So if that is set then you know it came from your site and not the other, than after the check unset that variable incase they decide to leave and comeback without closing the browser. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/#findComment-708587 Share on other sites More sharing options...
Yesideez Posted December 7, 2008 Author Share Posted December 7, 2008 Why didn't I think of that??? I'll leave this unsolved until I leave just in case someone knows how to clear the referer. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/#findComment-708605 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 You may want to see if header Has this functionality. Where on the script that redirects set the header of the referrer. I think that would work, but not sure. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/#findComment-708608 Share on other sites More sharing options...
Yesideez Posted December 7, 2008 Author Share Posted December 7, 2008 Fixed. Thanks for the reminder link to php.net - I found the answer to my problem there. header('Refresh: 0; url=index.php?re=direct'); This changes the HTTP_REFERER variable to that of my site which means links aren't logged twice any more. Quote Link to comment https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/#findComment-708619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.