// 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 ');}