PHP prohibits individual IP access to websites

Source: Internet
Author: User

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;} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.