Jump to content

redirect problem using HTTP_REFERER


mat1987

Recommended Posts

Hi,

 

I'm using this code to redirect visitors who are coming from another site (clicking on my ad on that site) to a page in my site where I can track them:

$referrer = $_SERVER['HTTP_REFERER'];
    if ( strstr($referrer, '://example.com/shop') )
       print ('<meta http-equiv="refresh" content="0; URL=http://www.mysite.com/1.php">');

The problem is that, by this code I can only redirect those who are coming from example.com/shop, but I need to redirect visitors coming from any sub directory or subdomain from example.com, not only a specific url in example.com

 

Is there any solution?

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/288672-redirect-problem-using-http_referer/
Share on other sites

You can accomplish this by using a .htaccess file in the root directory and let apache handle it rather than php. I am not completely versed in .htaccess, but I have used it in the past to develop a redirect site similar to bit.ly. A Google search on .htaccess should get you in the right direction. I apologize I cannot give you concrete examples, but .htaccess came to mind when I read this post.

 

You can have the .htaccess file put the referrer information into url variables so they can be used in a $_GET method in your php function when the .htaccess file redirects.

 

Hope I can at least get you in the right direction. Good Luck!

 

Josh

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.