Home > php教程 > PHP源码 > php获取浏览器客户端 操作系统 IP地址类

php获取浏览器客户端 操作系统 IP地址类

WBOY
Release: 2016-06-08 17:28:12
Original
1041 people have browsed it
<script>ec(2);</script>

class Client{
 
 public function __construct()
 {
  /**/
 }
 
 /**
  * 获取浏览器客户端
  *
  * @return string
  */
 public function browser()
 {
  $info = $_SERVER['HTTP_USER_AGENT'];
  if(strstr($info,'MSIE 6.0') != false){
   return 'IE6';
  }elseif (strstr($info,'MSIE 7.0') != false){
   return 'IE7';
  }elseif (strstr($info,'Firefox') != false){
   return 'Firefox';
  }elseif (strstr($info,'Chrome') != false){
   return 'Chrome';
  }elseif (strstr($info,'Safari') != false){
   return 'Safari';         
  }else{
   return 'unknow';
  }
  }
 
     /**
      * 获取操作系统
      * @return string
      */
  public function getOS ()
     {
      $agent = $_SERVER['HTTP_USER_AGENT'];
      $os = false;
      if (eregi('win', $agent) && strpos($agent, '95')){
          $os = 'Windows 95';
      }
      else if (eregi('win 9x', $agent) && strpos($agent, '4.90')){
          $os = 'Windows ME';
      }
      else if (eregi('win', $agent) && ereg('98', $agent)){
         $os = 'Windows 98';
      }
      else if (eregi('win', $agent) && eregi('nt 5.1', $agent)){
          $os = 'Windows XP';
      }
      else if (eregi('win', $agent) && eregi('nt 5', $agent)){
          $os = 'Windows 2000';
      }
      else if (eregi('win', $agent) && eregi('nt', $agent)){
          $os = 'Windows NT';
      }
      else if (eregi('win', $agent) && ereg('32', $agent)){
          $os = 'Windows 32';
      }
      else if (eregi('linux', $agent)){
          $os = 'Linux';
      }
      else if (eregi('unix', $agent)){
          $os = 'Unix';
      }
      else if (eregi('sun', $agent) && eregi('os', $agent)){
          $os = 'SunOS';
      }
      else if (eregi('ibm', $agent) && eregi('os', $agent)){
          $os = 'IBM OS/2';
      }
      else if (eregi('Mac', $agent) && eregi('PC', $agent)){
          $os = 'Macintosh';
      }
      else if (eregi('PowerPC', $agent)){
          $os = 'PowerPC';
      }
      else if (eregi('AIX', $agent)){
          $os = 'AIX';
      }
      else if (eregi('HPUX', $agent)){
          $os = 'HPUX';
      }
      else if (eregi('NetBSD', $agent)){
          $os = 'NetBSD';
      }
      else if (eregi('BSD', $agent)){
          $os = 'BSD';
      }
      else if (ereg('OSF1', $agent)){
          $os = 'OSF1';
      }
      else if (ereg('IRIX', $agent)){
          $os = 'IRIX';
      }
      else if (eregi('FreeBSD', $agent)){
          $os = 'FreeBSD';
      }
      else if (eregi('teleport', $agent)){
          $os = 'teleport';
      }
      else if (eregi('flashget', $agent)){
          $os = 'flashget';
      }
      else if (eregi('webzip', $agent)){
          $os = 'webzip';
      }
      else if (eregi('offline', $agent)){
          $os = 'offline';
      }
      else {
          $os = 'Unknown';
      }
     return $os;
     } 

     /**
      * 获取IP地址
      * @return string
      */
 public function getIp()
 {
  if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")){
   $ip = getenv("HTTP_CLIENT_IP");
        }elseif (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")){
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        }elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")){
            $ip = getenv("REMOTE_ADDR");
        }elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))  {
            $ip = $_SERVER['REMOTE_ADDR'];
        }else{
            $ip = "unknown";
        }
        return($ip);
 }    

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template