-
-
// 作用取得客戶端的ip、地理資訊、瀏覽器
- class get_gust_info {
- ////取得訪客瀏覽器型別
- function GetBrowser(){
- if(!empty($_SERVER['HTTP_USER_AGENT'])){
- $br = $_SERVER['HTTP_USER_AGENT'];
- $br = $_SERVER['HTTP_USER_AGENT'];
- $br = $_SERVER['HTTP_USER_AGENT'];
- if' /MSIE/i',$br)) {
- $br = 'MSIE';
- }elseif (preg_match('/Firefox/i',$br)) {
- $br = 'Firefox' ;
- }elseif (preg_match('/Chrome/i',$br)) {
- $br = 'Chrome';
- }elseif (preg_match('/Safari/i',$br)) {
- $br = 'Safari';
- }elseif (preg_match('/Opera/i',$br)) {
- $br = 'Opera';
- }else {
- $br = 'Other';
- }
- return $br;
- }else{return "取得瀏覽器資訊失敗!";}
- }
-
- ////取得訪客瀏覽器語言
- function GetLang(){
- if(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
- $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
- $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
- $ 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['HTTP_USER_AGENT'])){
- $OS = $_SERVER['HTTP_USER_AGENT'];
- if (preg_match('/win/i',$OS)) {
- $OS = 'Windows';
- }elseif (preg_match('/ mac/i',$OS)) {
- $OS = 'MAC';
- }elseif (preg_match('/linux/i',$OS)) {
- $OS = 'Linux';
- }elseif (preg_match('/unix/i',$OS)) {
- $OS = 'Unix';
- }elseif (preg_match('/bsd/i',$OS)) {
- $OS = 'BSD';
- }else {
- $OS = 'Other';
- }
- return $OS;
- }else{return "取得訪客作業系統資訊資訊失敗! ";}
- }
-
- ////取得訪客真實ip
- function Getip(){
- if(!empty($_SERVER["HTTP_CLIENT_IP"])){
- $ip = $_SERVER["HTTP_CLIENT_IP"];
- }
- if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ //取得代理ip
- $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- }
- if($ip){
- $ips = array_unshift($ips,$ip);
- }
-
- <. count> for($i=0;$i if(!preg_match("/^(10|172.16|192.168)./i",$ ips[$i])){//排除區域網路ip
- $ip = $ips[$i];
- break;
- }
- }
- $tip = empty($_SERVER[ 'REMOTE_ADDR']) ? $ip : $_SERVER['REMOTE_ADDR'];
- if($tip=="127.0.0.1"){ //取得本地真實IP
- return $this->get_onlineip() ;
- }else{
- return $tip;
- }
- }
-
- ////獲得本地真實IP
- function get_onlineip() {
- $mip = file_get_contents("http://city.ip138.com/city0.asp");
- if($mip){
- preg_match("/[.*]/",$mip,$sip);
- $p = array("/[/","/]/");
- return preg_replace($p,"",$sip[0]);
- }else{return "取得本地IP失敗! ";}
- }
-
- ////依ip取得訪客所在地地名
- function Getaddress($ip=''){
- if(empty($ip)){
- $ip = $this->Getip();
- }
- $ipadd = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=".$ ip);//根據新浪api介面取得
- if($ipadd){
- $charset = iconv("gbk","utf-8",$ipadd);
- preg_match_all("/[x {4e00}-x{9fa5}]+/u",$charset,$ipadds);
-
- return $ipadds; //回傳一個二維陣列
- }else{return "addree is none" ;}
- }
- }
- $gifo = new get_gust_info();
- echo "你的ip:".$gifo->Getip();
- echo "
所在地:";
- $ipadds = $gifo->Getaddress();
- foreach($ipadds[0] as $value){
- echo "rn ".iconv("utf-8","gbk ",$value);
- }
-
- echo "
瀏覽器類型:".$gifo->GetBrowser();
echo " 瀏覽器語言:" .$gifo->GetLang(); echo " 作業系統:".$gifo->GetOs(); ?>
複製程式碼 >>> 您可能有興趣的文章:
取得使用者真實IP位址的php代碼
php 取得外網真實IP的二種方法
php取得準確的客戶端IP位址的程式碼
php取得客戶端的真實IP的方法介紹
PHP透過IP取得地理位置的代碼
php取得網站地理位置及作業系統資訊的程式碼分享
php透過IP取得地理位置的實例參考
php 取得使用者真實IP與地理位置(淘寶IP介面)的實作代碼
php依IP位址取得目前地理位置介面
|