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


<?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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.