env.class.php 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * 环境类
  4. *
  5. * 收集常用的获得服务器端或客户端的环境参数的函数
  6. *
  7. * @createtime 2018/03/01
  8. * @author 空竹
  9. * @copyright 芝麻开发 (http://www.zhimawork.com)
  10. */
  11. class Env {
  12. /**
  13. * 获得当前页面的URL地址
  14. */
  15. static public function getPageUrl(){
  16. $url = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
  17. $url .= $_SERVER['HTTP_HOST'];
  18. $url .= $_SERVER['REQUEST_URI'];
  19. return $url;
  20. }
  21. /**
  22. * 获取当前的操作系统是Linux还是Windows
  23. */
  24. static public function getOSType(){
  25. $ostype = (DIRECTORY_SEPARATOR == '\\') ? "windows" : 'linux';
  26. return $ostype;
  27. }
  28. /**
  29. * 获得访问者IP
  30. */
  31. static public function getIP(){
  32. if (getenv("HTTP_CLIENT_IP"))
  33. $ip = getenv("HTTP_CLIENT_IP");
  34. else if(getenv("HTTP_X_FORWARDED_FOR"))
  35. $ip = getenv("HTTP_X_FORWARDED_FOR");
  36. else if(getenv("REMOTE_ADDR"))
  37. $ip = getenv("REMOTE_ADDR");
  38. else
  39. $ip = "unknown";
  40. return $ip;
  41. }
  42. }
  43. ?>