PHP Control access code based on IP address _php tutorial

Source: Internet
Author: User
Assuming there is an IP address range of 192.168.0.0~192.168.0.255, only the code that allows this IP segment to access is as follows:
Copy CodeThe code is as follows:
$IP = $_server[' remote_addr ');
$from = strcmp ($IP, ' 192.168.0.0 ');
$to = strcmp ($IP, ' 192.168.0.255 ');
if (! ( $from >= 0 && $to <= 0))
echo "Access Denied";
Else
echo "Homepage";
?>

From the process, this code first captures the guest IP address and then determines whether the IP address meets the access criteria. Conform to the normal output page, and vice versa Access denied.

Thus, if the user IP address satisfies the requirements, simply output or include the paging file. The file contains the following code:
Copy CodeThe code is as follows:
if (! ( $from >= 0 && $to <= 0))
echo "Access Denied";
Else
Include (' homepage.html ');
?>

Of course, you can also jump to different pages by judging the results. The jump code is as follows:
Copy CodeThe code is as follows:
if (! ( $from >= 0 && $to <= 0))
Header (' location:http://www.jb51.net/404.html ');
Else
Header (' location:http://www.jb51.net/index.html ');
?>

http://www.bkjia.com/PHPjc/321726.html www.bkjia.com true http://www.bkjia.com/PHPjc/321726.html techarticle Assuming that there is an IP address range of 192.168.0.0~192.168.0.255, only the code that allows this IP segment to be accessed is as follows: Copy code code as follows: PHP $IP = $_server[' remote_addr '); $from = strcmp ( $IP, ' ...

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