PHP prohibits individual IP access to their own website, you can look at the following methods.
functionGet_ip_data () {$ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip ()); $ip= Json_decode ($ip); if($ip-code) { return false; } $data= (Array)$ip-data; if($data[' Region ']== ' Guangdong province ' &&!Iscrawler ()) { Exit(' http://afish.cnblogs.com '); }} functionIscrawler () {$spiderSite=Array( "Tencenttraveler", "baiduspider+", "Baidugame", "Goog Lebot "," MSNBot "," sosospider+ "," Sogou web Spider ", "Ia_archiver", "Yahoo! slurp", "Youdaobot", "Yahoo slurp", "MSNBot", "Java (Often spam bot)", "Baiduspider", "Voila", "Yandex bot", "BSp Ider "," Twiceler "," Sogou spider "," Speedy spider ", "Google AdSense", "Heritrix", "Python-urllib", "Alexa (IA archiver)", "Ask", "Exabot", "Custo", "Outfoxbot/yodaobot", "YaCy", "Surveybot", "Legs", "lwp-trivial", "Nutch", "Stackrambler", "The Web Archive (IA archiver)", "Perl Tool", "Mj12bot", "Netcraft", "Msiecrawler", "WGet tools", "Larbin", "Fish search", ); if(In_array(Strtolower($_server[' Http_user_agent ']),$spiderSite)){ return true; }Else{ return false; }} //ReceivedFetch Client IPfunctionget_client_ip () {if(isset($_server)){ if(isset($_server["Http_x_forwarded_for"])){ $realip=$_server["Http_x_forwarded_for"]; } Else if(isset($_server["Http_client_ip"])) { $realip=$_server["Http_client_ip"]; } Else { $realip=$_server["REMOTE_ADDR"]; } } Else { if(getenv("Http_x_forwarded_for")){ $realip=getenv("Http_x_forwarded_for"); } Else if(getenv("Http_client_ip")) { $realip=getenv("Http_client_ip"); } Else { $realip=getenv("REMOTE_ADDR"); } } return $realip;}