Home > Backend Development > PHP Tutorial > PHP determines whether the visiting IP address is domestic or foreign

PHP determines whether the visiting IP address is domestic or foreign

WBOY
Release: 2016-07-25 09:04:13
Original
4694 people have browsed it
Copy code

Option 2: Use the IP library to determine the visiting IP address Advantages: Accurate judgment. Disadvantages: The response speed is not as fast as Javascript. You need to reference a PHP IP library: /Files/tianxin2001x/ip.zip

Quote jquery at the head of the website for judgment:

  1. ...
Copy the code

checkip.php file code:

  1. $userip=$_SERVER['REMOTE_ADDR'];

  2. //Reference the files of the ip library and put all the files in ip.zip in the lib directory
  3. include_once('/lib/ iplimit.class.php');
  4. $iplimit = new iplimit;

  5. if($iplimit->setup($userip))

  6. {
  7. echo 1;
  8. }
  9. else
  10. {
  11. echo 2;
  12. }

Copy code

Both of the above two methods can be used to determine the visiting IP address, choose one and use it.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template