How does PHP determine whether a user is accessed through a mobile phone?

Source: Internet
Author: User
// If HTTP_X_WAP_PROFILE exists, it must be a mobile device. // if the via information contains wap, it must be a mobile device. some service providers will block this information. // Determine the client ID sent by the mobile phone, compatibility to be improved // search for mobile browser keywords from HTTP_USER_AGENT
/*** Determine whether it is accessed by mobile phone */if (! Function_exists ('ismobile') {function isMobile () {// if there is HTTP_X_WAP_PROFILE, it must be a mobile device if (isset ($ _ SERVER ['http _ X_WAP_PROFILE ']) return TRUE; // if the via information contains wap, it must be a mobile device. some service providers will block this information if (isset ($ _ SERVER ['http _ vean']). {// cannot be found as flase; otherwise, it is truereturn stristr ($ _ SERVER ['http _ pass'], "wap ")? True: false;} // identifies the client flag sent by the mobile phone. the compatibility needs to be improved if (isset ($ _ SERVER ['http _ USER_AGENT ']). {$ clientkeywords = array ('Nokia ', 'Sony', 'ericsson ', 'MOT', 'Samsung', 'HTC ', 'sgh', 'LG ', 'Sharp ', 'sie-', 'Philips ', 'panasonic', 'alcatel', 'Lenovo ', 'iPhone', 'iPod ', 'BlackBerry ', 'meizu', 'Android', 'netfront', 'symbian ', 'ucweb', 'windowsce', 'Palm ', 'operamini', 'operamobi', 'openwave ', 'nexusone', 'cldc', 'midp ', 'wap', 'mobile'); // from HTTP_USER_AG If (preg_match ('/('. implode ('|', $ clientkeywords ). ')/I', strtolower ($ _ SERVER ['http _ USER_AGENT ']) {return TRUE ;}// resolution method, because it may be inaccurate, put it at the end to determine if (isset ($ _ SERVER ['http _ ACCEPT ']) {// if only wml is supported and html is not supported, it must be a mobile device // if wml and html are supported, but wml is a mobile device before html (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ')! = False) & (strpos ($ _ SERVER ['http _ ACCEPT '], 'text/html ') === false | (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ') <strpos ($ _ SERVER ['http _ ACCEPT'], 'text/html ') {return TRUE ;}} return FALSE ;}} // Obtain the urlif (! Function_exists ('getcururl') {function GetCurUrl () {if (! Empty ($ _ SERVER ['request _ URI ']) {$ nowurls = explode ('? ', $ _ SERVER ['request _ URI']); $ nowurl = $ nowurls [0];} else {$ nowurl = $ _ SERVER ['php _ SELF '];} return $ nowurl ;}}
 
 
 
 

Redirect processing

 

// Determine the access device if (IsMobile ()&&! Strstr (GetCurUrl (), '3G. php') {header ('Location: 3g. php ');}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.