Home >Backend Development >PHP Tutorial >PHP implements the class of reading the mobile client browser, PHP client_PHP tutorial
The example in 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 function class introduced here has the functions of obtaining mobile phone number, browser header information, obtaining mobile phone type, obtaining mobile phone IP and other functions.
class mobile{
/**
* Function name: getPhoneNumber
* Function: Get mobile phone number
* Input parameters: none
* Function return value: Returns the number if successful, false if failed
* Other instructions: Description
*/
function getPhoneNumber(){
if (isset($_SERVER[ 'HTTP_X_NETWORK_INFO '])){
$str1 = $_SERVER[ 'HTTP_X_NETWORK_INFO '];
$getstr1 = preg_replace( '/(.*,)(11[d])(,.*)/i ', '2 ',$str1);
Return $getstr1;
}elseif (isset($_SERVER[ 'HTTP_X_UP_CALLING_LINE_ID '])){
$getstr2 = $_SERVER[ 'HTTP_X_UP_CALLING_LINE_ID '];
Return $getstr2;
}elseif (isset($_SERVER[ 'HTTP_X_UP_SUBNO '])){
$str3 = $_SERVER[ 'HTTP_X_UP_SUBNO '];
$getstr3 = preg_replace( '/(.*)(11[d])(.*)/i ', '2 ',$str3);
Return $getstr3;
}elseif (isset($_SERVER[ 'DEVICEID '])){
Return $_SERVER[ 'DEVICEID '];
}else{
Return false;
}
}
/**
* Function name: getHttpHeader
* Function: Get header information
* Input parameters: none
* Function return value: Returns the number if successful, false if failed
* Other instructions: Description
*/
function getHttpHeader(){
$str = ' ';
foreach ($_SERVER as $key=> $val){
$gstr = str_replace( "& ", "& ",$val);
$str.= "$key -> ".$gstr. "rn ";
}
Return $str;
}
/**
* Function name: getUA
* Function function: Get UA
* Input parameters: none
* Function return value: Returns the number if successful, false if failed
* Other instructions: Description
*/
function getUA(){
if (isset($_SERVER[ 'HTTP_USER_AGENT '])){
Return $_SERVER[ 'HTTP_USER_AGENT '];
}else{
Return false;
}
}
/**
* Function name: getPhoneType
* Function: Get mobile phone type
* Input parameters: none
* Function return value: Returns string if successful, false if failed
* Other instructions: Description
*/
function getPhoneType(){
$ua = $this-> getUA();
if($ua!=false){
$str = explode( ' ',$ua);
Return $str[0];
}else{
Return false;
}
}
/**
* Function name: isOpera
* Function: Determine whether it is opera
* Input parameters: none
* Function return value: Returns string if successful, false if failed
* Other instructions: Description
*/
function isOpera(){
$uainfo = $this-> getUA();
if (preg_match( '/.*Opera.*/i ',$uainfo)){
Return true;
}else{
Return false;
}
}
/**
* Function name: isM3gate
* Function: Determine whether it is m3gate
* Input parameters: none
* Function return value: Returns string if successful, false if failed
* Other instructions: Description
*/
function isM3gate(){
$uainfo = $this-> getUA();
if (preg_match( '/M3Gate/i ',$uainfo)){
Return true;
}else{
Return false;
}
}
/**
* Function name: getHttpAccept
* Function: Obtain HA
* Input parameters: none
* Function return value: Returns string if successful, false if failed
* Other instructions: Description
*/
function getHttpAccept(){
if (isset($_SERVER[ 'HTTP_ACCEPT '])){
Return $_SERVER[ 'HTTP_ACCEPT '];
}else{
Return false;
}
}
/**
* Function name: getIP
* Function: Get mobile phone IP
* Input parameters: none
* Function return value: Successfully returns string
* Other instructions: Description
*/
function getIP(){
$ip=getenv( 'REMOTE_ADDR ');
$ip_ = getenv( 'HTTP_X_FORWARDED_FOR ');
if (($ip_ != " ") && ($ip_ != "unknown ")){
$ip=$ip_;
}
return $ip;
}
}
?>
I hope this article will be helpful to everyone’s PHP programming design.