Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect based on referrer URL

In my site I have a password protected page containing some links to other sites also operated by myself that cannot be password protected. I would like to place a HTML code onto one of the other sites I operate that checks that the person arriving at the page has been referred from the URL of the 'Links Page'.

(I understand that this is not a secure option)

Summary:

If Referrer = 'Links Page URL' *then* Do nothing *Else* Redirect: www.google.com.

Does anyone know a simple HTML/ Javascript code that I can copy and paste into my site?

like image 795
JBithell Avatar asked Dec 10 '13 18:12

JBithell


People also ask

What is URL referrer?

The address of the webpage where a person clicked a link that sent them to your page. The referrer is the webpage that sends visitors to your site using a link. In other words, it's the webpage that a person was on right before they landed on your page.

How do I find the URL of a referrer?

To check the Referer in action go to Inspect Element -> Network check the request header for Referer like below. Referer header is highlighted. Supported Browsers: The browsers are compatible with HTTP header Referer are listed below: Google Chrome.

What is document referrer?

The Document. referrer property returns the URI of the page that linked to this page.


1 Answers

if (document.referrer !== "http://www.stackoverflow.com") {
    window.location.href = "http://www.google.com";
}

Or you can use regular expressions to check the referrer.

Anyway, this solution is really, really unsafe. You can just turn off JavaScript in your browser and won't be redirected...

like image 159
Martin Majer Avatar answered Oct 23 '22 09:10

Martin Majer