ThinkPHP3.2 determine whether to access the phone and jump to another module method
directory structure Common module Common,home module, Mobile module Configuration Application/common/conf/config.php File'module_allow_list'='Home,mobile'Next Configure Application/common/common/function.php File Add IsMobile method "See Code Snippet 1" function IsMobile () {//If you have http_x_wap_profile, it must be a mobile device . if(Isset ($_server['Http_x_wap_profile'])) return true; //This article is excerpted from the TPM Smart Switch template engine for TPM development if(Isset ($_server['http_client']) &&'phoneclient'==$_server['http_client']) return true; //if the VIA message contains a WAP, it must be a mobile device, and some service providers block that information if(Isset ($_server['Http_via'])) //not found for flase, otherwise true returnStristr ($_server['Http_via'],'WAP') ?true:false; //determine the client flag sent by the phone, 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' ); //find keywords for your phone's browser from Http_user_agent if(Preg_match ("/(". Implode ('|', $clientkeywords).") /I", Strtolower ($_server['http_user_agent']))) { return true; } } //protocol law, because there may be inaccuracies, put to the final Judgment 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 if((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;} Configuration/application/home/controller/commoncontroller.class. PHP [public class] "See Code Snippet 2" Publicfunction _initialize () {if(IsMobile ()) {C ('Default_module','Mobile'); }} Configuration/application/mobile/controller/commoncontroller.class. PHP [public class] "See Code Snippet 3" Publicfunction _initialize () {if(!IsMobile ()) {C ('Default_module','Home'); }}