Use IP address location to restrict remote Logon of website background accounts

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange the learning principle. In fact, it is very simple to use the IP address library of TP to obtain the IP address of the user accessing the background, then obtain the country information and make a judgment.
Not much nonsense, go straight to the topic:
First, download the UTFWry. dat file (based on the website encoding and file name) and put it in the directory of the same level as the IpLocation. class. php file. If yes, skip it.

Then, simply add the following code at the beginning of the logon method of the background logon controller: $ IP = new \ Org \ Net \ IpLocation ('utfwry. dat ');
$ Area = $ IP-> getlocation ();
// Logon region detection. logon from unusual locations is rejected.
If (strstr ($ area ['country'], 'shanghai') = false ){
Exit ('you don \'t have permission to access! ');
}
The code above will detect the IP address of the user accessing the background. If the IP address is not in the range of "Shanghai", the user will be rejected. Is it simple? Just a few lines of code!
If you need more powerful functions, you can create an address library that allows you to log on to. The above addresses are detected cyclically.

Although it is not a good method, it is very practical and takes effect immediately after modification!

If you have other better ideas, please feel free to discuss them more ~~

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.