Php implements the class for reading the browser of the mobile client, php client. Php implements the class for reading the browser of the mobile client. The php client instance in this article describes the class for reading the browser of the mobile client. Share it with you for your reference. The specific analysis is as follows: php implements the class for reading the browser of the mobile client, and php client
This example describes how to use php to read the browser of a mobile client. Share it with you for your reference. The specific analysis is as follows:
The mobile phone information function class described here provides functions such as obtaining mobile phone numbers, browser header information, obtaining mobile phone types, and obtaining mobile phone IP addresses.
The code is as follows:
<? Php
/**
* Class name: mobile
* Description: mobile phone information.
* Others: accidental writing
*/
Class mobile {
/**
* Function name: getPhoneNumber
* Function: obtains the mobile phone number.
* Input parameter: none
* Function return value: the number is returned successfully. if the function fails, false is returned.
* 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: obtains the header information.
* Input parameter: none
* Function return value: the number is returned successfully. if the function fails, false is returned.
* 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: UA
* Input parameter: none
* Function return value: the number is returned successfully. if the function fails, false is returned.
* Other instructions: Description
*/
Function getUA (){
If (isset ($ _ SERVER ['http _ USER_AGENT ']) {
Return $ _ SERVER ['http _ USER_AGENT '];
} Else {
Return false;
}
}
/**
* Function name: getPhoneType
* Function: obtains the mobile phone type.
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function getPhoneType (){
$ Ua = $ this-> getUA ();
If ($ ua! = False ){
$ Str = explode ('', $ ua );
Return $ str [0];
} Else {
Return false;
}
}
/**
* Function name: isOpera
* Function: determines whether it is opera.
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function isOpera (){
$ Uainfo = $ this-> getUA ();
If (preg_match ('/. * Opera. */I', $ uainfo )){
Return true;
} Else {
Return false;
}
}
/**
* Function name: ismreceivate
* Function: determines whether it is mshortate.
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function ismreceivate (){
$ Uainfo = $ this-> getUA ();
If (preg_match ('/mshortate/I', $ uainfo )){
Return true;
} Else {
Return false;
}
}
/**
* Function name: getHttpAccept
* Function: obtain the HA
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function getHttpAccept (){
If (isset ($ _ SERVER ['http _ ACCEPT ']) {
Return $ _ SERVER ['http _ ACCEPT '];
} Else {
Return false;
}
}
/**
* Function name: getIP
* Function: obtain the mobile IP address.
* Input parameter: none
* Function return value: string is returned successfully.
* 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 help you with php programming.
Examples in this article describe the php class used to read the browser of the mobile client. Share it with you for your reference. The specific analysis is as follows :...