PHP prohibits individual IP addresses from accessing the website. If you want to prevent an IP address from accessing the website, you can block the IP address. this method is provided below. See the following code. The code for copying the code is as follows: functionget_ip_data () {$ ipfile_get_contents (ht can block an IP address from accessing the website. this method is provided below. See the following code.
The code is as follows:
Function get_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'] = 'hubei province '&&! IsCrawler ()){
Exit ('http: // www.a.net ');
}
}
Function isCrawler (){
$ SpiderSite = array (
"TencentTraveler ",
"Baiduspider + ",
"BaiduGame ",
"Googlebot ",
"Msnbot ",
"Sosospider + ",
"Sogou web spider ",
"Ia_archiver ",
"Yahoo! Slurp ",
"YoudaoBot ",
"Yahoo Slurp ",
"MSNBot ",
"Java (Often spam bot )",
"Baidusp ",
"Voila ",
"Yandex bot ",
"BSpider ",
"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;
}
}
// Obtain the client ip address
Function get_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;
}
Bytes. See the following code. The code is as follows: function get_ip_data () {$ ip = file_get_contents ("ht...