Home >php教程 >PHP源码 >php 获取客户端的ip、地理信息、浏览器信息、本地真实ip

php 获取客户端的ip、地理信息、浏览器信息、本地真实ip

PHP中文网
PHP中文网Original
2016-05-25 17:09:371280browse


<?php
 // 作用取得客户端的ip、地理信息、浏览器http://blog.qita.in
 class get_gust_info { 
  
  ////获得访客浏览器类型
  function GetBrowser(){
   if(!empty($_SERVER[&#39;HTTP_USER_AGENT&#39;])){
    $br = $_SERVER[&#39;HTTP_USER_AGENT&#39;];
    if (preg_match(&#39;/MSIE/i&#39;,$br)) {    
               $br = &#39;MSIE&#39;;
             }elseif (preg_match(&#39;/Firefox/i&#39;,$br)) {
     $br = &#39;Firefox&#39;;
    }elseif (preg_match(&#39;/Chrome/i&#39;,$br)) {
     $br = &#39;Chrome&#39;;
       }elseif (preg_match(&#39;/Safari/i&#39;,$br)) {
     $br = &#39;Safari&#39;;
    }elseif (preg_match(&#39;/Opera/i&#39;,$br)) {
        $br = &#39;Opera&#39;;
    }else {
        $br = &#39;Other&#39;;
    }
    return $br;
   }else{return "获取浏览器信息失败!";} 
  }
  
  ////获得访客浏览器语言
  function GetLang(){
   if(!empty($_SERVER[&#39;HTTP_ACCEPT_LANGUAGE&#39;])){
    $lang = $_SERVER[&#39;HTTP_ACCEPT_LANGUAGE&#39;];
    $lang = substr($lang,0,5);
    if(preg_match("/zh-cn/i",$lang)){
     $lang = "简体中文";
    }elseif(preg_match("/zh/i",$lang)){
     $lang = "繁体中文";
    }else{
        $lang = "English";
    }
    return $lang;
    
   }else{return "获取浏览器语言失败!";}
  }
  
   ////获取访客操作系统
  function GetOs(){
   if(!empty($_SERVER[&#39;HTTP_USER_AGENT&#39;])){
    $OS = $_SERVER[&#39;HTTP_USER_AGENT&#39;];
      if (preg_match(&#39;/win/i&#39;,$OS)) {
     $OS = &#39;Windows&#39;;
    }elseif (preg_match(&#39;/mac/i&#39;,$OS)) {
     $OS = &#39;MAC&#39;;
    }elseif (preg_match(&#39;/linux/i&#39;,$OS)) {
     $OS = &#39;Linux&#39;;
    }elseif (preg_match(&#39;/unix/i&#39;,$OS)) {
     $OS = &#39;Unix&#39;;
    }elseif (preg_match(&#39;/bsd/i&#39;,$OS)) {
     $OS = &#39;BSD&#39;;
    }else {
     $OS = &#39;Other&#39;;
    }
          return $OS;  
   }else{return "获取访客操作系统信息失败!";}   
  }
  
  ////获得访客真实ip
  function Getip(){
   if(!empty($_SERVER["HTTP_CLIENT_IP"])){   
      $ip = $_SERVER["HTTP_CLIENT_IP"];
   }
   if(!empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])){ //获取代理ip
    $ips = explode(&#39;,&#39;,$_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]);
   }
   if($ip){
      $ips = array_unshift($ips,$ip); 
   }
   
   $count = count($ips);
   for($i=0;$i

                   

Statement:
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