I have used below code to redirect specific IP address to specific page/website. It is working fine in Google Chrome but in Firefox and Internet Explorer, I am getting Error : "The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
Code:
<?php
$visitor = $_SERVER['REMOTE_ADDR'];
if(preg_match("/192.168.1.187/",$visitor)) {
header('Location: http://yahoo.com');
}
else {
header('Location: http://www.google.com');
};
?>
Seems like there is an endless redirect to the URL , Clear your cookies once and try adding HTTPS before the URLs and give a shot.
Also add an exit
or die
after your header
function. That will do.
Like..
<?php
$visitor = $_SERVER['REMOTE_ADDR'];
if(preg_match("/192.168.1.187/",$visitor)) {
header('Location: https://yahoo.com');
exit; //<-- Here
}
else {
header('Location: https://www.google.com');
exit; //<-- Here
};
?>
Tested the script in Nightly 29 (Firefox). I didnt get an error at all. But you should add exit
behind each header
so the script interrupts. And maybe you should add www
in front of the yahoo homepage.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.