Blogger Information
Blog 7
fans 0
comment 1
visits 11580
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP 获取IP地址
Original
3017 people have browsed it
  1. <?php
  2. /**
  3. * 客户端IP,
  4. * @return array|false|string
  5. */
  6. function getIP(){
  7. if (getenv("HTTP_CLIENT_IP"))
  8. $ip = getenv("HTTP_CLIENT_IP");
  9. else if(getenv("HTTP_X_FORWARDED_FOR"))
  10. $ip = getenv("HTTP_X_FORWARDED_FOR");
  11. else if(getenv("REMOTE_ADDR"))
  12. $ip = getenv("REMOTE_ADDR");
  13. else $ip = "Unknow";
  14. if(preg_match('/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/', $ip))
  15. return $ip;
  16. else
  17. return '';
  18. }
  19. /**
  20. * 服务器端IP
  21. * @return string
  22. */
  23. function serverIP(){
  24. return gethostbyname($_SERVER["SERVER_NAME"]);
  25. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post