PHP creates an instance code for abnormal logon ip address detection, and an ip address instance
Implement database traversal through function Query
/*** Do not return the red information when logging on to a common ip Address * @ param string $ name username * @ return string */function errorIp ($ ip, $ name) {$ nowip = get_client_ip (); // checks whether the ip address and the current ip address are the same. if ($ ip = $ nowip) {// returns the same string $ str = '<font color = "blue "'. "> logon IP Address :". $ ip. "</font>";} else {// The number of IP addresses in different records $ count = M ('log ') -> where ("name = '{$ name}' AND ip = '{$ ip}'")-> count (); // if a certain number of ip addresses are exceeded, a normal ip address is returned. Otherwise, an exception is returned. if ($ count> 10) {$ str = '<font color = "blue "'. "> logon IP Address :". $ ip. "</font>";} else {$ str = '<font color = "red "'. "> abnormal IP Address :". $ ip. "</font>" ;}} return $ str ;}
Note: This function is applicable to all frameworks. get_client_ip () is a function for obtaining ip addresses.
Get_client_ip function segment:
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 example code of the PHP login abnormal ip detection function is all the content that I have shared with you. I hope to give you a reference, and I hope you can provide more support for the house of friends.