Using function Query Database traversal implementation
/**
* Does not log on to the usual IP address alphabet information
* @param string $ip IP Address
* @param string $name username
* @return string
* *
function Errorip ($ip, $name) {
$nowip = Get_client_ip ();
Determine whether the IP and current IP are the same, different query database compare
if ($ip = = $nowip) {
//same direct return string
$str = ' <font color= ' blue '. ' > Login IP: ". $ip." </font> ";
} else{
//The number of this IP address is
$count = M (' log ')->where ("Name= ' {$name} ' and ip= ' {$ip} '")->count ();
If more than a certain number is normal IP otherwise the exception returns the string
if ($count >) {
$str = ' <font color= ' Blue '. > Login IP: ". $ip." </font> ";
} else{
$str = ' <font color= ' red '. ' > Abnormal IP: ". $ip." </font> ";
}
}
return $str;
}
Note: For all frameworks, Get_client_ip () is an IP capture 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 ('
REMOTE _addr ') && strcasecmp (getenv (' remote_addr '), ' unknown ') {
$ip = getenv (' remote_addr ');
} else{
$ ip = $_server[' remote_addr '];
}
return $ip;
}
Above this PHP to make login abnormal IP detection function of the example code is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.