First, a section of PHP code to determine whether to browse for mobile phone:
function IsMobile () {///If there is http_x_wap_profile, it must be a mobile device if (Isset ($_server[' http_x_wap_profile ')) {retur n true; }//If the VIA information contains WAP it must be a mobile device, some service associations block the information if (Isset ($_server[' Http_via ')) {//Cannot find for flase, otherwise true re Turn stristr ($_server[' Http_via '), "WAP")? True:false; }//Brain residue method, determine the mobile phone sent by the client flag, 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 OID ', ' 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 it must be a mobile device. If WML and HTML are supported but WML is before HTML the mobile device if ((Strpos ($_server[' http_accept '), ' VND.WAP.WML ')!== false) && (STRP OS ($_server[' http_accept '), ' text/html ') = = = False | | (Strpos ($_server[' http_accept '), ' vnd.wap.wml ') < Strpos ($_server[' http_accept '], ' text/html ')))) {return true; }} return false;}
Create two templates in the Phpcms template file:
The files in the content are PC-side templates, and the files in Content_m are mobile-side templates.
Second, edit the phpcms/modules/content/index.php in Pgpcms
Put the above PHP code in the class of index.
Find all of:
Include template (' content ', $template);
To be replaced by:
if ($this->ismobile ()) {include template (' Content_m ', $template);} Else{include template (' content ', $template);
In the end:
Include template (' content ', ' index ', $default _style);
To be replaced by:
if ($this->ismobile ()) {include template (' Content_m ', ' index ', $default _style);} Else{include template (' content ', ' index ', $default _style);}
So far, it's basically set up. When running the index.php file in Phpcms, the synchronization of the mobile phone and the PC-side database is achieved based on whether different templates are called for the phone end.
PHP to determine phone segment login, and PHPCMS mobile phone PC dual template calls