How to block another domain to access and get result from my website?

Trainee Asked on October 12, 2019 in Cpanel.
Add Comment
1 Answer(s)

Try checking the user agent if it is not a browser Firefox , safari …Deny accessing this will freak out the other domain that is copying your pages example:

if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE){
//Internet Explorer Good
}else{
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE){
//FireFox Good
}else{
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE){
//Chrome Good
}else{
//Check for safari , Opera , AndroidBrowser and IOS browser , Internet Explorer Mobile and text phones
//else run this code
die("Acessing this site is only allowed from this domain example.com"); 
}
}
}

EDIT:

append this code to your .htaccess

BrowserMatchNoCase SpammerRobot bad_bot
BrowserMatchNoCase SecurityHoleRobot bad_bot
Order Deny,Allow
Deny from env=bad_bot

As people have said in comment the user agent is empty:

if(empty($_SERVER['HTTP_USER_AGENT'])){
die("Error");
}

You could also apply the ip address so it will be harder for the other domain to break you:

You can also check for the UserOperating system but it is not required as it will may cause problem for some users so just don’t do it but it still a good idea.

Reviewer Answered on October 12, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.