php 取得客户端IP地址代码

  1. <?
  2. //开源代码
  3. function getip(){
  4. if (getenv("http_client_ip") && strcasecmp(getenv("http_client_ip"), "unknown"))
  5. $ip = getenv("http_client_ip"); //开源
  6. else if (getenv("http_x_forwarded_for") && strcasecmp(getenv("http_x_forwarded_for"), "unknown"))
  7. $ip = getenv("http_x_forwarded_for"); //
  8. else if (getenv("remote_addr") && strcasecmp(getenv("remote_addr"), "unknown"))
  9. $ip = getenv("remote_addr");
  10. else if (isset($_server[@#remote_addr@#]) && $_server[@#remote_addr@#] && strcasecmp($_server[@#remote_addr@#], "unknown"))
  11. //
  12. $ip = $_server[@#remote_addr@#];
  13. else
  14. $ip = "unknown";
  15. return($ip);
  16. }
  17. ?>
  18. 判断邮箱地址
  19. <?
  20. function checkemail($inaddress)
  21. {
  22. return (ereg("^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+",$inaddress));
  23. } //phpfensi.com
  24. ?>
  25. <?
  26. function getip() { //获取ip
  27. if ($_server["http_x_forwarded_for"])
  28. $ip = $_server["http_x_forwarded_for"]; //
  29. else if ($_server["http_client_ip"])
  30. $ip = $_server["http_client_ip"];
  31. else if ($_server["remote_addr"])
  32. $ip = $_server["remote_addr"]; //
  33. else if (getenv("http_x_forwarded_for"))
  34. $ip = getenv("http_x_forwarded_for");
  35. else if (getenv("http_client_ip"))
  36. $ip = getenv("http_client_ip"); //
  37. else if (getenv("remote_addr"))
  38. $ip = getenv("remote_addr");
  39. else
  40. $ip = "unknown";
  41. return $ip;
  42. }
  43. ?>