PHP How to set a background IP segment can login? _php Tutorials

Source: Internet
Author: User
Sometimes we hope that the website of Changsha address IP can log in and other areas of IP login, the following I will write a PHP program this can be implemented to restrict the background of an IP segment can login OH.

The code is as follows Copy Code
Public Function login () {
Set IP Segment Login
if (getenv ("Http_client_ip")) {
$onlineip = getenv (' http_client_ip ');
}
ElseIf (getenv (' http_x_forwarded_for ')) {
$onlineip = getenv (' http_x_forwarded_for ');
}
ElseIf (getenv (' remote_addr ')) {
$onlineip = getenv (' remote_addr ');
}
else{
$onlineip = $HTTP _server_vars[' remote_addr ');
}
Echo $onlineip;
$adminip = $onlineip;
$arrayip = Array (' 117.121.48.* ', ' 127.0.0.* ');//IP segment
$ipregexp = implode (' | ', Str_replace (Array (' * ', '. '), Array (' d+ ', '. '), $arrayip));
$allow = Preg_match ("/^ (". $ipregexp. ") $/", $adminip);

if ($allow! = 1) {
ShowMessage (' Your IP address is not in the allowed range! '), ' m=admin&c=index&a=login ', 6000);
}

Put the following code into your website login portal call, and then change the m=admin&c=index&a=login to your address on it.

http://www.bkjia.com/PHPjc/633159.html www.bkjia.com true http://www.bkjia.com/PHPjc/633159.html techarticle Sometimes we hope that the website of Changsha address IP can log in and other areas of IP login, the following I will write a PHP program this can be implemented to restrict the background of an IP segment can login Oh ...

  • 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.