ThinkPHP3.2 determine whether it is accessed by the Mobile phone and jump to the method of another module. The directory structure is Common, Home, and Mobile modules. The Mobile module configures ApplicationCommonConfconfig. php file MODULE_ALLOW_LISTHome. Mobile then configures ApplicationCommonCommonfunction.
ThinkPHP3.2 determine whether it is accessed by the Mobile phone end and jump to the method of another module. The directory structure is Common, Home, and Mobile modules. Configure Application/Common/Conf/config. PHP file MODULE_ALLOW_LIST = Home, Mobile then configure Application/Common/function. add isMobil to the PHP File
ThinkPHP3.2 how to determine whether the client is accessed by a mobile phone and jump to another module
Directory structure
Common, Home, and Mobile modules
Configure the Application/Common/Conf/config. php file
'Module _ ALLOW_LIST '=> 'home, Mobile'
Next, configure the Application/Common/function. php file.
Add an isMobile method. For details, see section 1]
Configure/Application/Home/Controller/CommonController. class. php [public class]
For details, see section 2]
Configure/Application/Mobile/Controller/CommonController. class. php [public class]
[See section 3] ThinkPHP
Function isMobile () {// if HTTP_X_WAP_PROFILE exists, it must be a mobile device if (isset ($ _ SERVER ['HTTP _ X_WAP_PROFILE ']) return true; // This is taken from TPM intelligent switch template engine. It is suitable for TPM to develop if (isset ($ _ SERVER ['HTTP _ client']). & 'phoneclient' ==$ _ SERVER ['HTTP _ client']) return true; // If the via information contains wap, it must be a mobile device, some service providers shield this information if (isset ($ _ SERVER ['HTTP _ VIA ']) // cannot find flase, otherwise, it is true return stristr ($ _ SERVER ['HTTP _ pass'], 'wap ')? True: false; // determine 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 '); // _ USER_AGENT: Search for the keyword 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 ;}
public function _initialize(){ if(isMobile()){ C('DEFAULT_MODULE','Mobile'); } }
public function _initialize(){ if(!isMobile()){ C('DEFAULT_MODULE','Home'); } }