ThinkPHP3.2 determine whether to access the phone and jump to another module 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"
function IsMobile () {///If there is 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, suitable for TPM development if (Isset ($_server[' http_client ')) && ' phoneclient ' ==$_server[' http_client ']) r Eturn true; If VIA information contains WAP, it must be a mobile device, some service associations block the information if (Isset ($_server[' Http_via '))//cannot be found for flase, otherwise true return Stristr ($ _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 ', ' s Ony ', ' 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 '; Look for the keyword if (Preg_match ("/(") of the phone's browser from Http_user_agent. Implode (' | ', $clientkeywords). ")/I", Strtolower ($_server[' http_user_agent '))) { return true; }}//protocol method, because it may not be accurate, put to the Last Judgment if (Isset ($_server[' http_accept ')) {//If only WML is supported and HTML is not supported that must be mobile//IF Support for WML and HTML but WML before HTML is the mobile device if ((Strpos ($_server[' http_accept '), ' VND.WAP.WML ')!== false) && (Strpos ($_se rver[' http_accept '], ' text/html ') = = = False | | (Strpos ($_server[' http_accept '), ' vnd.wap.wml ') < Strpos ($_server[' http_accept '], ' text/html ')))) {return true; }} return false;}
Configure /application/home/controller/commoncontroller. class . PHP [public class] "See Code"
Public Function _initialize () { if (IsMobile ()) { C (' default_module ', ' Mobile ');} }
Configuration /application/mobile/controller/commoncontroller. class . PHP [public class] "See Code"
Public Function _initialize () { if (!ismobile ()) { C (' default_module ', ' Home ');} }
ThinkPHP3.2 determine how to access and set the default Access module on the phone