//作用取得客戶端的ip、地理信息、瀏覽器、本地真實(shí)IP
class get_gust_info {
////獲得訪客瀏覽器類型
function GetBrowser(){
if(!empty($_SERVER['HTTP_USER_AGENT'])){
$br = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/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 "獲取瀏覽器信息失??!";}
}
////獲得訪客瀏覽器語(yǔ)言
function GetLang(){
if(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($lang,0,5);
if(preg_match("/zh-cn/i",$lang)){
$lang = "簡(jiǎn)體中文";
}elseif(preg_match("/zh/i",$lang)){
$lang = "繁體中文";
}else{
$lang = "English";
}
return $lang;
}else{return "獲取瀏覽器語(yǔ)言失敗!";}
}
////獲取訪客操作系統(tǒng)
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 "獲取訪客操作系統(tǒng)信息失??!";}
}
////獲得訪客真實(shí)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 = count($ips);
for($i=0;$i<$count;$i++){
if(!preg_match("/^(10|172.16|192.168)./i",$ips[$i])){//排除局域網(wǎng)ip
$ip = $ips[$i];
break;
}
}
$tip = empty($_SERVER['REMOTE_ADDR']) ? $ip : $_SERVER['REMOTE_ADDR'];
if($tip=="127.0.0.1"){ //獲得本地真實(shí)IP
return $this->get_onlineip();
}else{
return $tip;
}
}
////獲得本地真實(shí)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失??!";}
}
////根據(jù)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);//根據(jù)新浪api接口獲取
if($ipadd){
$charset = iconv("gbk","utf-8",$ipadd);
preg_match_all("/[x{4e00}-x{9fa5}]+/u",$charset,$ipadds);
return $ipadds; //返回一個(gè)二維數(shù)組
}else{return "addree is none";}
}
}
$gifo = new get_gust_info();
echo "你的ip:".$gifo->Getip();
echo "所在地:";
$ipadds = $gifo->Getaddress();
foreach($ipadds[0] as $value){
echo " ".iconv("utf-8","gbk",$value);
}
echo "瀏覽器類型:".$gifo->GetBrowser();
echo "瀏覽器語(yǔ)言:".$gifo->GetLang();
echo "操作系統(tǒng):".$gifo->GetOs();
?>
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: eyoucms易優(yōu)擴(kuò)展客戶端ip地理信息瀏覽器本地真實(shí)IP示例代碼