Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/135931-solved-clearing-http_referer/
Share on other sites

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.