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

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

May 25, 2016 pm 05:09 PM


<?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
Copy after login

                   

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)