Access webpages Based on IP address restrictions

Source: Internet
Author: User
There is no research on PHP, and there is a page on the website that requires only on-campus access. Google has spent half a day trying to use the online materials for half a day, so I am in a hurry to use it, I had to send a post to Cu to ask, and soon I got the answer. It's good for the Forum. Haha, despite the suspicion of being lazy :) after the test, I have to study hard. No way, work is needed.

This is the simplest way to determine an independent IP address.
<? PHP
// Allowed IP Address
$ Allowip = array (
'1970. 168.1.11 ',
'1970. 168.1.22 ',
'1970. 168.1.33 ',
);

$ IP = $ _ server ["remote_addr"];
If (! In_array ($ IP, $ allowip ))
{
Echo "Access forbid! ";
Exit;
}
?>
<HTML> some contetn ....

The IP segment is also very simple:

<? PHP
// Allowed IP segments
$ Allowip = array (
'2017. 123 ',
'2017. 123 ',
'2017. 123 ',
);

$ IP = explode ('.', $ _ server ["remote_addr"]);
Array_pop ($ IP );
$ IP = implode ('.', $ IP );

If (! In_array ($ IP, $ allowip ))
{
Echo "Access forbid! ";
Exit;
}
?>
<HTML> some contetn ....
 

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.