简体   繁体   English

将特定IP地址重定向到PHP中的特定页面

[英]Redirection of specific IP address to specific page in PHP

I have used below code to redirect specific IP address to specific page/website. 我使用下面的代码将特定的IP地址重定向到特定的页面/网站。 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." 在Google Chrome浏览器中,它工作正常,但是在Firefox和Internet Explorer中,我收到错误消息 :“页面无法正确重定向。Firefox已检测到服务器正在以永远无法完成的方式重定向对该地址的请求。”

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. 似乎有无限的重定向到URL,一次清除您的cookie并尝试在URL之前添加HTTPS并尝试一下。

Also add an exit or die after your header function. 还可以在header函数之后添加exitdie 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). 在Nightly 29(Firefox)中测试了脚本。 I didnt get an error at all. 我根本没有得到一个错误。 But you should add exit behind each header so the script interrupts. 但是您应该在每个header后面添加exit ,以便脚本中断。 And maybe you should add www in front of the yahoo homepage. 也许您应该在yahoo主页前添加www

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM