Example of PHP making login exception IP detection function

Source: Internet
Author: User
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.