Add judgment code to the Home Module index controller
application\home\controller\indexcontroller.class.php
<?php//+----------------------------------------------------------------------//| OPENCMF [Simple efficient excellent]//+----------------------------------------------------------------------//| Copyright (c) http://www.opencmf.cn All rights reserved.//+---------------------------------------------------- ------------------// | Author:jry <[email protected]>//+------------------------------------------------------------------- ---namespace home\controller;use think\controller;/** * Front default controller * @author jry <[email protected]> */class Indexcontroller extends HomeController {/** * default method * @author jry <[email protected]> * * Publ IC function Index () {Cookie (' __forward__ ', C (' home_page ')); if ($this->ismobile ()) {$this->redirect ('/cms/index/lists/cid/1.html ');//To redirect the phone to the mobile module} if (c (' Index_url ')) {if (Stristr (' C (' Index_url '), ' HTTP//') | | stristr (c (' Index_url '), ' Https://')) {redirect (C (' Index_url ')); } else {$this->redirect (C (' Index_url ')); }} $this->assign (' Meta_title ', "Home"); $this->display (); } 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 and is suitable for TPM development if (Isset ($_server[' http_client ') && ' phoneclient ' ==$_server[' http_client ') return 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 Retu RN 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 ', ' 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 '); 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 a move Mobile device//If WML and HTML are supported, but WML is before HTML it is the move device 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; }}
IsMobile Judging method comes from the network.
Corethink Development (11) Home Controller Judge Mobile device or PC and do the corresponding processing