This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13862|Reply: 6

php gets the IP address of the client

[Copy link]
Posted on 2/24/2015 12:54:53 PM | | |
This post was last edited by test on 2015-2-24 12:58
  1. <?php
  2. function getIp() {
  3.     if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP");
  4.     else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR");
  5.     else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR");
  6.     else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR'];
  7.     else $ip = "unknown";
  8.     return ($ip);
  9. }
  10. echo getIp();
  11. ?>
Copy code
See for yourself, do not explain.




Previous:declaration methods and call methods in PHP
Next:php to get client information (browser/IP/operating system) code
Posted on 11/8/2017 3:22:37 PM |
Yes, I learned
Posted on 6/8/2022 4:15:24 PM |
Thank you, studied
Posted on 9/7/2022 11:56:15 AM |
How do I show that it is::1, is there something wrong with this code?
Posted on 9/24/2022 2:08:34 PM |
Prompt:Authors are banned or removed content is automatically blocked
Posted on 1/18/2023 3:34:55 PM |
Learn it!!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com