How to read the class sample code of mobile client browser in php

怪我咯
Release: 2023-03-12 17:22:01
Original
1152 people have browsed it

This article mainly introduces the PHP class for reading mobile client browsers, which can be used to obtain mobile phone numbers, browser header information, obtain mobile phone types, obtain mobile phone IP and other functions. Friends who need it can refer to the following

The example of this article describes the PHP class that implements reading the mobile client browser. Share it with everyone for your reference. The specific analysis is as follows:

The mobile phone information introduced hereFunction class has the functions of obtaining mobile phone number, browser header information, obtaining mobile phone type, obtaining mobile phone IP and other functions.

The code is as follows:

<?php 
/** 
*   类名:   mobile 
*   描述:   手机信息类 
*   其他:   偶然   编写 
*/
class   mobile{ 
/** 
*   函数名称:   getPhoneNumber 
*   函数功能:   取手机号 
*   输入参数:   none 
*   函数返回值:   成功返回号码,失败返回false 
*   其它说明:   说明 
*/ 
function   getPhoneNumber(){ 
if   (isset($_SERVER[ &#39;HTTP_X_NETWORK_INFO &#39;])){ 
$str1   =   $_SERVER[ &#39;HTTP_X_NETWORK_INFO &#39;]; 
$getstr1   =   preg_replace( &#39;/(.*,)(11[d])(,.*)/i &#39;, &#39;2 &#39;,$str1); 
Return   $getstr1; 
}elseif   (isset($_SERVER[ &#39;HTTP_X_UP_CALLING_LINE_ID &#39;])){ 
$getstr2   =   $_SERVER[ &#39;HTTP_X_UP_CALLING_LINE_ID &#39;]; 
Return   $getstr2; 
}elseif   (isset($_SERVER[ &#39;HTTP_X_UP_SUBNO &#39;])){ 
$str3   =   $_SERVER[ &#39;HTTP_X_UP_SUBNO &#39;]; 
$getstr3   =   preg_replace( &#39;/(.*)(11[d])(.*)/i &#39;, &#39;2 &#39;,$str3); 
Return   $getstr3; 
}elseif   (isset($_SERVER[ &#39;DEVICEID &#39;])){ 
Return   $_SERVER[ &#39;DEVICEID &#39;]; 
}else{ 
Return   false; 
} 
}
/** 
*   函数名称:   getHttpHeader 
*   函数功能:   取头信息 
*   输入参数:   none 
*   函数返回值:   成功返回号码,失败返回false 
*   其它说明:   说明 
*/ 
function   getHttpHeader(){ 
$str   =   &#39; &#39;; 
foreach   ($_SERVER   as   $key=> $val){ 
$gstr   =   str_replace( "& ", "& ",$val); 
$str.=   "$key   ->   ".$gstr. "rn "; 
} 
Return   $str; 
}
/** 
*   函数名称:   getUA 
*   函数功能:   取UA 
*   输入参数:   none 
*   函数返回值:   成功返回号码,失败返回false 
*   其它说明:   说明 
*/ 
function   getUA(){ 
if   (isset($_SERVER[ &#39;HTTP_USER_AGENT &#39;])){ 
Return   $_SERVER[ &#39;HTTP_USER_AGENT &#39;]; 
}else{ 
Return   false; 
} 
}
/** 
*   函数名称:   getPhoneType 
*   函数功能:   取得手机类型 
*   输入参数:   none 
*   函数返回值:   成功返回string,失败返回false 
*   其它说明:   说明 
*/ 
function   getPhoneType(){ 
$ua   =   $this-> getUA(); 
if($ua!=false){ 
$str   =   explode( &#39;   &#39;,$ua); 
Return   $str[0]; 
}else{ 
Return   false; 
} 
}
/** 
*   函数名称:   isOpera 
*   函数功能:   判断是否是opera 
*   输入参数:   none 
*   函数返回值:   成功返回string,失败返回false 
*   其它说明:   说明 
*/ 
function   isOpera(){ 
$uainfo   =   $this-> getUA(); 
if   (preg_match( &#39;/.*Opera.*/i &#39;,$uainfo)){ 
Return   true; 
}else{ 
Return   false; 
} 
}
/** 
*   函数名称:   isM3gate 
*   函数功能:   判断是否是m3gate 
*   输入参数:   none 
*   函数返回值:   成功返回string,失败返回false 
*   其它说明:   说明 
*/ 
function   isM3gate(){ 
$uainfo   =   $this-> getUA(); 
if   (preg_match( &#39;/M3Gate/i &#39;,$uainfo)){ 
Return   true; 
}else{ 
Return   false; 
} 
}
/** 
*   函数名称:   getHttpAccept 
*   函数功能:   取得HA 
*   输入参数:   none 
*   函数返回值:   成功返回string,失败返回false 
*   其它说明:   说明 
*/ 
function   getHttpAccept(){ 
if   (isset($_SERVER[ &#39;HTTP_ACCEPT &#39;])){ 
Return   $_SERVER[ &#39;HTTP_ACCEPT &#39;]; 
}else{ 
Return   false; 
} 
}
/** 
*   函数名称:   getIP 
*   函数功能:   取得手机IP 
*   输入参数:   none 
*   函数返回值:   成功返回string 
*   其它说明:   说明 
*/ 
function   getIP(){ 
$ip=getenv( &#39;REMOTE_ADDR &#39;); 
$ip_   =   getenv( &#39;HTTP_X_FORWARDED_FOR &#39;); 
if   (($ip_   !=   " ")   &&   ($ip_   !=   "unknown ")){ 
$ip=$ip_; 
} 
return   $ip; 
} 
} 
?>
Copy after login


The above is the detailed content of How to read the class sample code of mobile client browser in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template