{"id":31318,"date":"2024-11-25T10:38:04","date_gmt":"2024-11-25T02:38:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31318\/"},"modified":"2024-11-25T10:38:04","modified_gmt":"2024-11-25T02:38:04","slug":"phpcms%e5%ae%9e%e7%8e%b0%e7%a7%bb%e5%8a%a8%e7%ab%af%e5%92%8c%e7%94%b5%e8%84%91%e7%ab%af%e4%b8%8d%e5%90%8c%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31318\/","title":{"rendered":"phpcms\u5b9e\u73b0\u79fb\u52a8\u7aef\u548c\u7535\u8111\u7aef\u4e0d\u540c\u6a21\u677f"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/040\/5e425db95db15884.jpg\" class=\"aligncenter\" title=\"phpcms\u5b9e\u73b0\u79fb\u52a8\u7aef\u548c\u7535\u8111\u7aef\u4e0d\u540c\u6a21\u677f\u63d2\u56fe\" alt=\"phpcms\u5b9e\u73b0\u79fb\u52a8\u7aef\u548c\u7535\u8111\u7aef\u4e0d\u540c\u6a21\u677f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b9e\u73b0\u79fb\u52a8\u7aef\u548c\u7535\u8111\u7aef\u4e0d\u540c\u6a21\u677f<\/strong><\/p>\n<p>1\u3001\u9996\u5148\u6253\u5f00phpcms\/libs\/functions\/global.func.php\uff0c\u5728\u6587\u4ef6\u6700\u540e\u9762\u52a0\u4e00\u4e2aisMobile()\u65b9\u6cd5\uff0c\u7528\u6765\u5224\u65ad\u662f\u5426\u662f\u624b\u673a\u7aef\u6253\u5f00<\/p>\n<pre>&nbsp;function&nbsp;isMobile()&nbsp;{\n&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c\u6709HTTP_X_WAP_PROFILE\u5219\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907\n&nbsp;&nbsp;if&nbsp;(isset($_SERVER['HTTP_X_WAP_PROFILE']))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\n&nbsp;&nbsp;}\n&nbsp;&nbsp;\/\/&nbsp;\u5982\u679cvia\u4fe1\u606f\u542b\u6709wap\u5219\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907,\u90e8\u5206\u670d\u52a1\u5546\u4f1a\u5c4f\u853d\u8be5\u4fe1\u606f\n&nbsp;&nbsp;if&nbsp;(isset($_SERVER['HTTP_VIA']))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u627e\u4e0d\u5230\u4e3aflase,\u5426\u5219\u4e3atrue\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;stristr($_SERVER['HTTP_VIA'],&nbsp;\"wap\")&nbsp;?&nbsp;true&nbsp;:&nbsp;false;\n&nbsp;&nbsp;}\n&nbsp;&nbsp;\/\/&nbsp;\u8111\u6b8b\u6cd5\uff0c\u5224\u65ad\u624b\u673a\u53d1\u9001\u7684\u5ba2\u6237\u7aef\u6807\u5fd7,\u517c\u5bb9\u6027\u6709\u5f85\u63d0\u9ad8\u3002\u5176\u4e2d'MicroMessenger'\u662f\u7535\u8111\u5fae\u4fe1\n&nbsp;&nbsp;if&nbsp;(isset($_SERVER['HTTP_USER_AGENT']))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;$clientkeywords&nbsp;=&nbsp;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','MicroMessenger');\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u4eceHTTP_USER_AGENT\u4e2d\u67e5\u627e\u624b\u673a\u6d4f\u89c8\u5668\u7684\u5173\u952e\u5b57\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(preg_match(\"\/(\"&nbsp;.&nbsp;implode('|',&nbsp;$clientkeywords)&nbsp;.&nbsp;\")\/i\",&nbsp;strtolower($_SERVER['HTTP_USER_AGENT'])))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n&nbsp;&nbsp;\/\/&nbsp;\u534f\u8bae\u6cd5\uff0c\u56e0\u4e3a\u6709\u53ef\u80fd\u4e0d\u51c6\u786e\uff0c\u653e\u5230\u6700\u540e\u5224\u65ad\n&nbsp;&nbsp;if&nbsp;(isset&nbsp;($_SERVER['HTTP_ACCEPT']))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c\u53ea\u652f\u6301wml\u5e76\u4e14\u4e0d\u652f\u6301html\u90a3\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c\u652f\u6301wml\u548chtml\u4f46\u662fwml\u5728html\u4e4b\u524d\u5219\u662f\u79fb\u52a8\u8bbe\u5907\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((strpos($_SERVER['HTTP_ACCEPT'],&nbsp;'vnd.wap.wml')&nbsp;!==&nbsp;false)&nbsp;&amp;amp;&amp;amp;&nbsp;(strpos($_SERVER['HTTP_ACCEPT'],&nbsp;'text\/html')&nbsp;===&nbsp;false&nbsp;||&nbsp;(strpos($_SERVER['HTTP_ACCEPT'],&nbsp;'vnd.wap.wml')&nbsp;&lt;p&gt;2\u3001\u7136\u540e\u6253\u5f00phpcms\/modules\/content\/index.php\uff0c\u6709\u4e09\u4e2a\u5730\u65b9\u8981\u6539\u7684&lt;\/p&gt;&lt;p&gt;a\uff09\u627e\u5230\u9996\u9875\u7684init\u65b9\u6cd5\uff0c\u5728\u6700\u540e\u52a0\u8f7d\u6a21\u677f\u7684\u65f6\u5019\uff0c\u505a\u4e00\u4e2a\u5224\u65ad\uff0c\u5982\u679c\u662f\u624b\u673a\u7aef\u6253\u5f00\u5c31\u52a0\u8f7d\u624b\u673a\u7aef\u6a21\u677f\uff0c\u5982\u679c\u662f\u7535\u8111\u7aef\u6253\u5f00\u5c31\u52a0\u8f7d\u7535\u8111\u7aef\u6a21\u677f&lt;\/p&gt;&lt;p&gt;\u5927\u6982\u572831\u884c\u627e\u5230:&lt;\/p&gt;&lt;p&gt;&lt;span&gt;\u7acb\u5373\u5b66\u4e60&lt;\/span&gt;\u201c&lt;a href=\"https:\/\/pan.quark.cn\/s\/7fc7563c4182\" style=\"text-decoration: underline !important; color: blue; font-weight: bolder;\" rel=\"nofollow\" target=\"_blank\"&gt;PHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09&lt;\/a&gt;\u201d\uff1b&lt;\/p&gt;&lt;pre class=\"brush:js;toolbar:false\"&gt;include&nbsp;template('content','index',$default_style);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6539\u6210:<\/p>\n<pre>if(isMobile()){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template('mobile','index',$default_style);\n}else{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template('content','index',$default_style);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>b\uff09\u627e\u5230\u5185\u5bb9\u9875\u7684show\u65b9\u6cd5\uff0c\u540c\u6837\u5728\u6700\u540e\u52a0\u8f7d\u6a21\u677f\u7684\u65f6\u5019\u505a\u4e00\u4e2a\u5224\u65ad<\/p>\n<p>\u5927\u6982\u5728203\u884c\u627e\u5230\uff1a<\/p>\n<pre>include&nbsp;template('content',$template);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6539\u6210\uff1a<\/p>\n<pre>if(isMobile()){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template('mobile',$template);\n}else{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template('content',$template);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>c\uff09\u627e\u5230\u5217\u8868\u9875\u7684lists\u65b9\u6cd5,\u540c\u6837\u5728\u6700\u540e\u52a0\u8f7d\u6a21\u677f\u7684\u65f6\u5019\u505a\u4e00\u4e2a\u5224\u65ad<\/p>\n<p>\u5927\u6982\u5728265\u884c\u548c278\u884c\uff0c\u8fd9\u91cc\u6709\u4e24\u5904\uff0c\u627e\u5230:<\/p>\n<pre>include&nbsp;template('content',$template);\n\u6539\u6210\uff1a\nif(isMobile()){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template('mobile',$template);}else{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template('content',$template);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4f60\u5f53\u524d\u7684\u6a21\u677f\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2amobile\u76ee\u5f55\uff0c\u7528\u6765\u5b58\u653e\u624b\u673a\u7aef\u6a21\u677f<\/p>\n<p>\u5982\u679c\u4f60\u5f53\u524d\u7684\u6a21\u677f\u76ee\u5f55\u662fphpcms\/templates\/default,\u90a3\u4e48\u4f60\u5c31\u5728phpcms\/templates\/default\u4e0b\u9762\u5efa\u4e00\u4e2amobile\u76ee\u5f55\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5f53\u524d\u7684\u6a21\u677f\u76ee\u5f55\u662fphpcms\/templates\/moban,\u90a3\u4e48\u4f60\u5c31\u5728phpcms\/templates\/moban\u4e0b\u9762\u5efa\u4e00\u4e2amobile\u76ee\u5f55\u3002<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u73b0\u7535\u8111\u7aef\u548c\u624b\u673a\u7aef\u5206\u522b\u52a0\u8f7d\u4e0d\u540c\u7684\u6a21\u677f\u3002<\/p>\n<p>PHP\u4e2d\u6587\u7f51\uff0c\u5927\u91cf\u7684\u514d\u8d39\uff0c\u6b22\u8fce\u5728\u7ebf\u5b66\u4e60\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b9e\u73b0\u79fb\u52a8\u7aef\u548c\u7535\u8111\u7aef\u4e0d\u540c\u6a21\u677f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u73b0\u79fb\u52a8\u7aef\u548c\u7535\u8111\u7aef\u4e0d\u540c\u6a21\u677f 1\u3001\u9996\u5148\u6253\u5f00phpcms\/libs\/functions\/global.func.php\uff0c\u5728\u6587\u4ef6\u6700\u540e\u9762\u52a0\u4e00\u4e2aisMobile()\u65b9\u6cd5\uff0c\u7528\u6765\u5224\u65ad\u662f\u5426\u662f\u624b\u673a\u7aef\u6253\u5f00 &nbsp;function&nbsp;isMobile()&nbsp;{ &nbsp;&nbsp;\/\/&nbsp;\u5982\u679c\u6709HTTP_X_WAP_PROFILE\u5219\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907 &nbsp;&nbsp;if&nbsp;(isset($_SERVER[&#8216;HTTP_X_WAP_PROFILE&#8217;]))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true; &nbsp;&nbsp;} &nbsp;&nbsp;\/\/&nbsp;\u5982\u679cvia\u4fe1\u606f\u542b\u6709wap\u5219\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907,\u90e8\u5206\u670d\u52a1\u5546\u4f1a\u5c4f\u853d\u8be5\u4fe1\u606f &nbsp;&nbsp;if&nbsp;(isset($_SERVER[&#8216;HTTP_VIA&#8217;]))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u627e\u4e0d\u5230\u4e3aflase,\u5426\u5219\u4e3atrue &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;stristr($_SERVER[&#8216;HTTP_VIA&#8217;],&nbsp;&#8220;wap&#8221;)&nbsp;?&nbsp;true&nbsp;:&nbsp;false; &nbsp;&nbsp;} &nbsp;&nbsp;\/\/&nbsp;\u8111\u6b8b\u6cd5\uff0c\u5224\u65ad\u624b\u673a\u53d1\u9001\u7684\u5ba2\u6237\u7aef\u6807\u5fd7,\u517c\u5bb9\u6027\u6709\u5f85\u63d0\u9ad8\u3002\u5176\u4e2d&#8217;MicroMessenger&#8217;\u662f\u7535\u8111\u5fae\u4fe1 &nbsp;&nbsp;if&nbsp;(isset($_SERVER[&#8216;HTTP_USER_AGENT&#8217;]))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;$clientkeywords&nbsp;=&nbsp;array(&#8216;nokia&#8217;,&#8217;sony&#8217;,&#8217;ericsson&#8217;,&#8217;mot&#8217;,&#8217;samsung&#8217;,&#8217;htc&#8217;,&#8217;sgh&#8217;,&#8217;lg&#8217;,&#8217;sharp&#8217;,&#8217;sie-&#8216;,&#8217;philips&#8217;,&#8217;panasonic&#8217;,&#8217;alcatel&#8217;,&#8217;lenovo&#8217;,&#8217;iphone&#8217;,&#8217;ipod&#8217;,&#8217;blackberry&#8217;,&#8217;meizu&#8217;,&#8217;android&#8217;,&#8217;netfront&#8217;,&#8217;symbian&#8217;,&#8217;ucweb&#8217;,&#8217;windowsce&#8217;,&#8217;palm&#8217;,&#8217;operamini&#8217;,&#8217;operamobi&#8217;,&#8217;openwave&#8217;,&#8217;nexusone&#8217;,&#8217;cldc&#8217;,&#8217;midp&#8217;,&#8217;wap&#8217;,&#8217;mobile&#8217;,&#8217;MicroMessenger&#8217;); &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u4eceHTTP_USER_AGENT\u4e2d\u67e5\u627e\u624b\u673a\u6d4f\u89c8\u5668\u7684\u5173\u952e\u5b57 &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(preg_match(&#8220;\/(&#8221;&nbsp;.&nbsp;implode(&#8216;|&#8217;,&nbsp;$clientkeywords)&nbsp;.&nbsp;&#8220;)\/i&#8221;,&nbsp;strtolower($_SERVER[&#8216;HTTP_USER_AGENT&#8217;])))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;} &nbsp;&nbsp;\/\/&nbsp;\u534f\u8bae\u6cd5\uff0c\u56e0\u4e3a\u6709\u53ef\u80fd\u4e0d\u51c6\u786e\uff0c\u653e\u5230\u6700\u540e\u5224\u65ad &nbsp;&nbsp;if&nbsp;(isset&nbsp;($_SERVER[&#8216;HTTP_ACCEPT&#8217;]))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c\u53ea\u652f\u6301wml\u5e76\u4e14\u4e0d\u652f\u6301html\u90a3\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907 &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c\u652f\u6301wml\u548chtml\u4f46\u662fwml\u5728html\u4e4b\u524d\u5219\u662f\u79fb\u52a8\u8bbe\u5907 &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((strpos($_SERVER[&#8216;HTTP_ACCEPT&#8217;],&nbsp;&#8216;vnd.wap.wml&#8217;)&nbsp;!==&nbsp;false)&nbsp;&amp;amp;&amp;amp;&nbsp;(strpos($_SERVER[&#8216;HTTP_ACCEPT&#8217;],&nbsp;&#8216;text\/html&#8217;)&nbsp;===&nbsp;false&nbsp;||&nbsp;(strpos($_SERVER[&#8216;HTTP_ACCEPT&#8217;],&nbsp;&#8216;vnd.wap.wml&#8217;)&nbsp;&lt;p&gt;2\u3001\u7136\u540e\u6253\u5f00phpcms\/modules\/content\/index.php\uff0c\u6709\u4e09\u4e2a\u5730\u65b9\u8981\u6539\u7684&lt;\/p&gt;&lt;p&gt;a\uff09\u627e\u5230\u9996\u9875\u7684init\u65b9\u6cd5\uff0c\u5728\u6700\u540e\u52a0\u8f7d\u6a21\u677f\u7684\u65f6\u5019\uff0c\u505a\u4e00\u4e2a\u5224\u65ad\uff0c\u5982\u679c\u662f\u624b\u673a\u7aef\u6253\u5f00\u5c31\u52a0\u8f7d\u624b\u673a\u7aef\u6a21\u677f\uff0c\u5982\u679c\u662f\u7535\u8111\u7aef\u6253\u5f00\u5c31\u52a0\u8f7d\u7535\u8111\u7aef\u6a21\u677f&lt;\/p&gt;&lt;p&gt;\u5927\u6982\u572831\u884c\u627e\u5230:&lt;\/p&gt;&lt;p&gt;&lt;span&gt;\u7acb\u5373\u5b66\u4e60&lt;\/span&gt;\u201c&lt;a href=&#8221;https:\/\/pan.quark.cn\/s\/7fc7563c4182&#8243; style=&#8221;text-decoration: underline !important; color: blue; font-weight: bolder;&#8221; rel=&#8221;nofollow&#8221; target=&#8221;_blank&#8221;&gt;PHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09&lt;\/a&gt;\u201d\uff1b&lt;\/p&gt;&lt;pre class=&#8221;brush:js;toolbar:false&#8221;&gt;include&nbsp;template(&#8216;content&#8217;,&#8217;index&#8217;,$default_style); \u767b\u5f55\u540e\u590d\u5236 \u6539\u6210: if(isMobile()){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template(&#8216;mobile&#8217;,&#8217;index&#8217;,$default_style); }else{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template(&#8216;content&#8217;,&#8217;index&#8217;,$default_style); } \u767b\u5f55\u540e\u590d\u5236 b\uff09\u627e\u5230\u5185\u5bb9\u9875\u7684show\u65b9\u6cd5\uff0c\u540c\u6837\u5728\u6700\u540e\u52a0\u8f7d\u6a21\u677f\u7684\u65f6\u5019\u505a\u4e00\u4e2a\u5224\u65ad \u5927\u6982\u5728203\u884c\u627e\u5230\uff1a include&nbsp;template(&#8216;content&#8217;,$template); \u767b\u5f55\u540e\u590d\u5236 \u6539\u6210\uff1a if(isMobile()){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template(&#8216;mobile&#8217;,$template); }else{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;template(&#8216;content&#8217;,$template); } \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-31318","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31318"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31318\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}