PHP implements the class of reading the mobile client browser, PHP client_PHP tutorial

WBOY
Release: 2016-07-13 10:09:59
Original
683 people have browsed it

php implements the class of reading the mobile client browser, php client

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.

Copy code The code is as follows:
/**
* Class name: mobile
* Description: Mobile phone information
* Others: Written by chance
*/

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/940490.htmlTechArticlephp implements the class of reading the mobile client browser, php client. This article describes the example of php implementing reading the mobile phone Class for client browsers. Share it with everyone for your reference. The specific analysis is as follows:...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!