Redirect Loop (HTTP_REFERER)

The website (wwww.fake-web-site.com) redirects its links to my website (www.real-web-site.com). Only the first page is different.

I wrote code to redirect all the people who came from a fake site to google.com.

if (strpos($_SERVER['HTTP_REFERER'],'fake-web-site.com') !== false) header('Location: http://www.google.com/search?q=real-web-site.com'); 

It works in the Chrome browser, if someone opens a fake website and clicks on the links that are associated with my site, it will be redirected to google.com. After that, he can open my site with google.com.

In Firefox, if someone opens a fake website and clicks on the links that are related to my site, he will be redirected to google.com after that, if he clicks on real-web-site.com on google.com, it redirects again to google.com!

I think this is due to the Firefox caching mechanism. Can someone give a suggestion?

+4
source share
1 answer

Redirecting browser caches. Depending on the status of the HTTP response:

If status 301 is permanently moved, the browser should, and possibly cache it.

If status 302 is found, the browser should not and will not cache it.

There is something else left in the browser. From your code, it seems that you are simply responding to 200 OK.

You can set the response header in PHP by doing, for example:

 header("HTTP/1.0 302 Found"); 

This should be done before any other body or header output — unless you use output buffering.

0
source

Source: https://habr.com/ru/post/1494021/


All Articles