Arvind
Arvind

Reputation: 1

Securing PHP website to restrain opening it on other domains

I want to secure the PHP website so that it does not work on any other domain except the one I am working on. I can give a error page or any other website name if someone tries to configure that website on his domain. Please help here.

Thanks, Arvind.

Upvotes: 0

Views: 35

Answers (2)

Philipos D.
Philipos D.

Reputation: 2310

You could use the php function $_SERVER["REMOTE_ADDR"] check the $_SERVER documentation.
Let's say that only you may enter the website, you could use.

if ($_SERVER["REMOATE_ADDR"] == "192.168.0.111") {
  echo "Allowed";
} else {
  echo "Not allowed";
}

Upvotes: 1

Abhishek Sharma
Abhishek Sharma

Reputation: 3300

You may use $_SERVER['SERVER_NAME'] to validate current domain name.

if(strpos($_SERVER['SERVER_NAME'], "yourdomain.com") !== -1){
    // valid case
}else{
    //redirect or throw error
}

Hope that works for you.

Upvotes: 2

Related Questions