PHP implements the method of limiting IP Access, and php implements ip Access
This article describes how to restrict IP Access in PHP. We will share this with you for your reference. The details are as follows:
// Obtain the client ipif (getenv ("HTTP_CLIENT_IP") $ ip = getenv ("HTTP_CLIENT_IP"); else if (getenv ("HTTP_X_FORWARDED_FOR ")) $ ip = getenv ("HTTP_X_FORWARDED_FOR"); else if (getenv ("REMOTE_ADDR") $ ip = getenv ("REMOTE_ADDR"); else $ ip = "Unknow "; $ ALLOWED_IP = array ('10. 144.39.132 '); // ip address $ check_ip_arr = explode ('. ', $ ip); // The ip parameter is split into an array if (! In_array ($ ip, $ ALLOWED_IP) {$ bl = false; foreach ($ ALLOWED_IP as $ val) {if (strpos ($ val ,'*')! = False) {// The * Replacement Code $ arr = array (); $ arr = explode ('. ', $ val); $ bl = true; // used to record whether a matched for ($ I = 0; $ I <4; $ I ++) {if ($ arr [$ I]! = '*') {// Not equal to *. Check if ($ arr [$ I]) is not checked if it is a * symbol replacement. = $ Check_ip_arr [$ I]) {$ bl = false; break; // stop checking this ip address and continue checking the next ip address }}// end for if ($ bl) {// if it is true, terminate matching break;} // end foreach if (! $ Bl) {$ return = array ('status' => 2, 'msg '=> 'this IP Address has no permission to access', 'data' => $ ip ); echo json_encode ($ return); exit ();}}