This article mainly introduces PHP production login exception IP detection Function example, interested in the friend's reference, I hope to help you.
Querying database traversal implementations using functions
/** * Do not return understandriginally information on a common IP address * @param string $IP IP Address * @param string $name username * @return String */function errorip ($ip, $name) { $nowip = Get_client_ip (); To determine whether the IP and current IP are the same, the query database compares if ($ip = = $nowip) { //the same direct return string $str = ' <font color= ' Blue '. " > Login IP: ". $ip." </font> "; } else{ //Different count this number of IP addresses $count = M (' log ')->where ("Name= ' {$name} ' and ip= ' {$ip} ')->count (); If more than a certain number is normal IP otherwise returns the string if ($count >) { $str = ' <font color= ' blue '. ' > Login IP: ". $ip." </font> "; } else{ $str = ' <font color= ' red '. ' > Exception IP: ". $ip." </font> "; } } return $STR;}
Note: Suitable for all frames, get_client_ip () is an IP get function.
Get_client_ip function Fragment:
function Get_client_ip () { if (getenv (' http_client_ip ') && strcasecmp (getenv (' http_client_ip '), ' Unknown ') { $ip = getenv (' http_client_ip '); } elseif (getenv (' http_x_forwarded_for ') && strcasecmp ( getenv (' http_x_forwarded_for '), ' unknown ') { $ip = getenv (' http_x_forwarded_for '); } elseif (getenv (' REMOTE _addr ') && strcasecmp (getenv (' remote_addr '), ' unknown ') { $ip = getenv (' remote_addr '); } else{ $ ip = $_server[' remote_addr '); } return $IP;}
The above is the whole content of this article, I hope that everyone's study has helped.