Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hey,

I want to allow only one specific domain to access one of my pages.

So for example: only if the user comes from www.google.com they can access www.mywebsite.com/restricted_page.

I have tried some referrer ways using php but none that are very well made.

Is it possible to only allow the IP address of the website to access my website page?

What I have tried:

<?php
    if ($_SERVER['HTTP_REFERER'] == "https://www.whatismyreferer.com/") {
        // continue
    } else {
        header("Location: https://www.whatismyreferer.com/");
        exit(); //Stop running the script
        // go to form page again.
    }
?>
Posted
Updated 30-Jun-18 1:30am
Comments

If you are looking to allow users who click on a google search result and not others, then using the referer header is a viable option.

Do note however that browsers will not send a referer header from a secure site (e.g. https://google.com) to an insecure site. You should enable https on your website to do this.

This option is also not very user-friendly for privacy-minded users who configure their browser to never send referer headers.
 
Share this answer
 
Use proxy 127.0.0.1 in connections tab and LAN settings
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900