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