{"id":23189,"date":"2024-11-21T08:56:16","date_gmt":"2024-11-21T00:56:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23189\/"},"modified":"2024-11-21T08:56:16","modified_gmt":"2024-11-21T00:56:16","slug":"thinkphp%e5%a6%82%e4%bd%95%e6%a0%b9%e6%8d%ae%e8%ae%be%e5%a4%87%e8%ae%bf%e9%97%ae%e4%b8%8d%e5%90%8c%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23189\/","title":{"rendered":"thinkphp\u5982\u4f55\u6839\u636e\u8bbe\u5907\u8bbf\u95ee\u4e0d\u540c\u6a21\u677f"},"content":{"rendered":"<\/p>\n<blockquote><p>\n  thinkphp\u6839\u636e\u8bbe\u5907\u8bbf\u95ee\u4e0d\u540c\u6a21\u677f\u7684\u65b9\u6cd5\uff1a1\u3001\u628a\u201cfunction isMobile(){&#8230;}\u201d\u653e\u5728\u201cappcommon.php\u201d\u516c\u5171\u65b9\u6cd5\u4e2d\uff1b2\u3001\u5728index\u6a21\u5757\u4e0b\u7684\u516c\u5171\u65b9\u6cd5\u5185\u8bbe\u7f6e\u524d\u7f6e\u64cd\u4f5c\uff1b3\u3001\u5224\u65ad\u4e3atrue\u5219\u6267\u884c\u201cmobile\/index\u201d\u65b9\u6cd5\uff0c\u5426\u5219\u6267\u884c\u53e6\u4e00\u4e2apc\u7aef\u7684\u63a7\u5236\u5668\u64cd\u4f5c\u5373\u53ef\u3002\n<\/p><\/blockquote>\n<p>5\u5224\u65ad\u79fb\u52a8\u6216pc\u7aef\u8bbf\u95ee\u5e76\u8c03\u7528\u4e0d\u540c\u6a21\u677f<\/p>\n<p>\u628a\u4e0b\u9762\u7684\u4ee3\u7801\u653e\u5728appcommon.php\u516c\u5171\u65b9\u6cd5\u90a3\u91cc\u3002<\/p>\n<pre>function&nbsp;isMobile()\n{\nif&nbsp;(isset($_SERVER[\u2018HTTP_X_WAP_PROFILE\u2019]))&nbsp;{\nreturn&nbsp;true;\n}\nif&nbsp;(isset($_SERVER[\u2018HTTP_VIA\u2019]))&nbsp;{\nreturn&nbsp;stristr($_SERVER[\u2018HTTP_VIA\u2019],&nbsp;\u201cwap\u201d)&nbsp;?&nbsp;true&nbsp;:&nbsp;false;\n}\nif&nbsp;(isset($_SERVER[\u2018HTTP_USER_AGENT\u2019]))&nbsp;{\n$clientkeywords&nbsp;=&nbsp;array(\u2018nokia\u2019,&nbsp;\u2018sony\u2019,&nbsp;\u2018ericsson\u2019,&nbsp;\u2018mot\u2019,&nbsp;\u2018samsung\u2019,&nbsp;\u2018htc\u2019,&nbsp;\u2018sgh\u2019,&nbsp;\u2018lg\u2019,&nbsp;\u2018sharp\u2019,&nbsp;\u2018sie-\u2018,&nbsp;\u2018philips\u2019,&nbsp;\u2018panasonic\u2019,&nbsp;\u2018alcatel\u2019,&nbsp;\u2018lenovo\u2019,&nbsp;\u2018iphone\u2019,&nbsp;\u2018ipod\u2019,&nbsp;\u2018blackberry\u2019,&nbsp;\u2018meizu\u2019,&nbsp;\u2018android\u2019,&nbsp;\u2018netfront\u2019,&nbsp;\u2018symbian\u2019,&nbsp;\u2018ucweb\u2019,&nbsp;\u2018windowsce\u2019,&nbsp;\u2018palm\u2019,&nbsp;\u2018operamini\u2019,&nbsp;\u2018operamobi\u2019,&nbsp;\u2018openwave\u2019,&nbsp;\u2018nexusone\u2019,&nbsp;\u2018cldc\u2019,&nbsp;\u2018midp\u2019,&nbsp;\u2018wap\u2019,&nbsp;\u2018mobile\u2019);\nif&nbsp;(preg_match(\u201c\/(\u201d&nbsp;.&nbsp;implode(\u2018|\u2019,&nbsp;$clientkeywords)&nbsp;.&nbsp;\u201c)\/i\u201d,&nbsp;strtolower($_SERVER[\u2018HTTP_USER_AGENT\u2019])))&nbsp;{\nreturn&nbsp;true;\n}\n}\nif&nbsp;(isset($_SERVER[\u2018HTTP_ACCEPT\u2019]))&nbsp;{\nif&nbsp;((strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018vnd.wap.wml\u2019)&nbsp;!==&nbsp;false)&nbsp;&amp;amp;&amp;amp;&nbsp;(strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018textml\u2019)&nbsp;===&nbsp;false&nbsp;||&nbsp;(strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018vnd.wap.wml\u2019)&nbsp;&lt;p&gt;\u518d\u5728index\u6a21\u5757\u4e0b\u7684\u516c\u5171\u65b9\u6cd5\u5185\u8bbe\u7f6e\u524d\u7f6e\u64cd\u4f5c\uff0c\u5982\u679c\u5224\u65ad\u4e3atrue\u5219\u6267\u884cmobile\/index\u65b9\u6cd5\uff08\u79fb\u52a8\u7aef\u7684\u63a7\u5236\u5668\uff09\uff0c\u5426\u5219\u5219\u6267\u884c\u53e6\u4e00\u4e2apc\u7aef\u7684\u63a7\u5236\u5668\u64cd\u4f5c&lt;\/p&gt;&lt;pre class=\"brush:php;toolbar:false\"&gt;public&nbsp;function&nbsp;_initialize(){\nif(isMobile()){\n$this-&amp;gt;redirect(\u2018mobile\/index\u2019);\n}\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u65b9\u6cd52<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u628a\u65b9\u6cd5\u653e\u5728app\/common\u3002php\u6587\u4ef6\u5939\u91cc\u9762<\/p>\n<pre>\/\/&nbsp;\u5e94\u7528\u516c\u5171\u6587\u4ef6\n\/\/\u5224\u65ad\u5ba2\u6237\u7aef\u8bbf\u95ee\u65b9\u5f0f\nfunction&nbsp;ismobile()&nbsp;{\n\/\/&nbsp;\u5982\u679c\u6709HTTP_X_WAP_PROFILE\u5219\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907\nif&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_X_WAP_PROFILE\u2019]))\nreturn&nbsp;true;\n\/\/\u6b64\u6761\u6458\u81eaTPM\u667a\u80fd\u5207\u6362\u6a21\u677f\u5f15\u64ce\uff0c\u9002\u5408TPM\u5f00\u53d1\nif(isset&nbsp;($_SERVER[\u2018HTTP_CLIENT\u2019])&nbsp;&amp;amp;&amp;amp;\u2019PhoneClient\u2019==$_SERVER[\u2018HTTP_CLIENT\u2019])\nreturn&nbsp;true;\n\/\/\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\nif&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_VIA\u2019]))\n\/\/\u627e\u4e0d\u5230\u4e3aflase,\u5426\u5219\u4e3atrue\nreturn&nbsp;stristr($_SERVER[\u2018HTTP_VIA\u2019],&nbsp;\u2018wap\u2019)&nbsp;?&nbsp;true&nbsp;:&nbsp;false;\n\/\/\u5224\u65ad\u624b\u673a\u53d1\u9001\u7684\u5ba2\u6237\u7aef\u6807\u5fd7,\u517c\u5bb9\u6027\u6709\u5f85\u63d0\u9ad8\nif&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_USER_AGENT\u2019]))&nbsp;{\n$clientkeywords&nbsp;=&nbsp;array(\n\u2018nokia\u2019,\u2019sony\u2019,\u2019ericsson\u2019,\u2019mot\u2019,\u2019samsung\u2019,\u2019htc\u2019,\u2019sgh\u2019,\u2019lg\u2019,\u2019sharp\u2019,\u2019sie-\u2018,\u2019philips\u2019,\u2019panasonic\u2019,\u2019alcatel\u2019,\u2019lenovo\u2019,\u2019iphone\u2019,\u2019ipod\u2019,\u2019blackberry\u2019,\u2019meizu\u2019,\u2019android\u2019,\u2019netfront\u2019,\u2019symbian\u2019,\u2019ucweb\u2019,\u2019windowsce\u2019,\u2019palm\u2019,\u2019operamini\u2019,\u2019operamobi\u2019,\u2019openwave\u2019,\u2019nexusone\u2019,\u2019cldc\u2019,\u2019midp\u2019,\u2019wap\u2019,\u2019mobile\u2019\n);\n\/\/\u4eceHTTP_USER_AGENT\u4e2d\u67e5\u627e\u624b\u673a\u6d4f\u89c8\u5668\u7684\u5173\u952e\u5b57\nif&nbsp;(preg_match(\u201c\/(\u201d&nbsp;.&nbsp;implode(\u2018|\u2019,&nbsp;$clientkeywords)&nbsp;.&nbsp;\u201c)\/i\u201d,&nbsp;strtolower($_SERVER[\u2018HTTP_USER_AGENT\u2019])))&nbsp;{\nreturn&nbsp;true;\n}\n}\n\/\/\u534f\u8bae\u6cd5\uff0c\u56e0\u4e3a\u6709\u53ef\u80fd\u4e0d\u51c6\u786e\uff0c\u653e\u5230\u6700\u540e\u5224\u65ad\nif&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_ACCEPT\u2019]))&nbsp;{\n\/\/&nbsp;\u5982\u679c\u53ea\u652f\u6301wml\u5e76\u4e14\u4e0d\u652f\u6301html\u90a3\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907\n\/\/&nbsp;\u5982\u679c\u652f\u6301wml\u548chtml\u4f46\u662fwml\u5728html\u4e4b\u524d\u5219\u662f\u79fb\u52a8\u8bbe\u5907\nif&nbsp;((strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018vnd.wap.wml\u2019)&nbsp;!==&nbsp;false)&nbsp;&amp;amp;&amp;amp;&nbsp;(strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018text\/html\u2019)&nbsp;===&nbsp;false&nbsp;||&nbsp;(strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018vnd.wap.wml\u2019)&nbsp;&lt;script type=\"text\/javascript\" src=\"https:\/\/sw.yisu.com\/hezuo\/43cc2463da342d2af2696436bd2d05f4.html?bottom\"&gt;&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u6839\u636e\u8bbe\u5907\u8bbf\u95ee\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>thinkphp\u6839\u636e\u8bbe\u5907\u8bbf\u95ee\u4e0d\u540c\u6a21\u677f\u7684\u65b9\u6cd5\uff1a1\u3001\u628a\u201cfunction isMobile(){&#8230;}\u201d\u653e\u5728\u201cappcommon.php\u201d\u516c\u5171\u65b9\u6cd5\u4e2d\uff1b2\u3001\u5728index\u6a21\u5757\u4e0b\u7684\u516c\u5171\u65b9\u6cd5\u5185\u8bbe\u7f6e\u524d\u7f6e\u64cd\u4f5c\uff1b3\u3001\u5224\u65ad\u4e3atrue\u5219\u6267\u884c\u201cmobile\/index\u201d\u65b9\u6cd5\uff0c\u5426\u5219\u6267\u884c\u53e6\u4e00\u4e2apc\u7aef\u7684\u63a7\u5236\u5668\u64cd\u4f5c\u5373\u53ef\u3002 5\u5224\u65ad\u79fb\u52a8\u6216pc\u7aef\u8bbf\u95ee\u5e76\u8c03\u7528\u4e0d\u540c\u6a21\u677f \u628a\u4e0b\u9762\u7684\u4ee3\u7801\u653e\u5728appcommon.php\u516c\u5171\u65b9\u6cd5\u90a3\u91cc\u3002 function&nbsp;isMobile() { if&nbsp;(isset($_SERVER[\u2018HTTP_X_WAP_PROFILE\u2019]))&nbsp;{ return&nbsp;true; } if&nbsp;(isset($_SERVER[\u2018HTTP_VIA\u2019]))&nbsp;{ return&nbsp;stristr($_SERVER[\u2018HTTP_VIA\u2019],&nbsp;\u201cwap\u201d)&nbsp;?&nbsp;true&nbsp;:&nbsp;false; } if&nbsp;(isset($_SERVER[\u2018HTTP_USER_AGENT\u2019]))&nbsp;{ $clientkeywords&nbsp;=&nbsp;array(\u2018nokia\u2019,&nbsp;\u2018sony\u2019,&nbsp;\u2018ericsson\u2019,&nbsp;\u2018mot\u2019,&nbsp;\u2018samsung\u2019,&nbsp;\u2018htc\u2019,&nbsp;\u2018sgh\u2019,&nbsp;\u2018lg\u2019,&nbsp;\u2018sharp\u2019,&nbsp;\u2018sie-\u2018,&nbsp;\u2018philips\u2019,&nbsp;\u2018panasonic\u2019,&nbsp;\u2018alcatel\u2019,&nbsp;\u2018lenovo\u2019,&nbsp;\u2018iphone\u2019,&nbsp;\u2018ipod\u2019,&nbsp;\u2018blackberry\u2019,&nbsp;\u2018meizu\u2019,&nbsp;\u2018android\u2019,&nbsp;\u2018netfront\u2019,&nbsp;\u2018symbian\u2019,&nbsp;\u2018ucweb\u2019,&nbsp;\u2018windowsce\u2019,&nbsp;\u2018palm\u2019,&nbsp;\u2018operamini\u2019,&nbsp;\u2018operamobi\u2019,&nbsp;\u2018openwave\u2019,&nbsp;\u2018nexusone\u2019,&nbsp;\u2018cldc\u2019,&nbsp;\u2018midp\u2019,&nbsp;\u2018wap\u2019,&nbsp;\u2018mobile\u2019); if&nbsp;(preg_match(\u201c\/(\u201d&nbsp;.&nbsp;implode(\u2018|\u2019,&nbsp;$clientkeywords)&nbsp;.&nbsp;\u201c)\/i\u201d,&nbsp;strtolower($_SERVER[\u2018HTTP_USER_AGENT\u2019])))&nbsp;{ return&nbsp;true; } } if&nbsp;(isset($_SERVER[\u2018HTTP_ACCEPT\u2019]))&nbsp;{ if&nbsp;((strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018vnd.wap.wml\u2019)&nbsp;!==&nbsp;false)&nbsp;&amp;amp;&amp;amp;&nbsp;(strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018textml\u2019)&nbsp;===&nbsp;false&nbsp;||&nbsp;(strpos($_SERVER[\u2018HTTP_ACCEPT\u2019],&nbsp;\u2018vnd.wap.wml\u2019)&nbsp;&lt;p&gt;\u518d\u5728index\u6a21\u5757\u4e0b\u7684\u516c\u5171\u65b9\u6cd5\u5185\u8bbe\u7f6e\u524d\u7f6e\u64cd\u4f5c\uff0c\u5982\u679c\u5224\u65ad\u4e3atrue\u5219\u6267\u884cmobile\/index\u65b9\u6cd5\uff08\u79fb\u52a8\u7aef\u7684\u63a7\u5236\u5668\uff09\uff0c\u5426\u5219\u5219\u6267\u884c\u53e6\u4e00\u4e2apc\u7aef\u7684\u63a7\u5236\u5668\u64cd\u4f5c&lt;\/p&gt;&lt;pre class=&#8221;brush:php;toolbar:false&#8221;&gt;public&nbsp;function&nbsp;_initialize(){ if(isMobile()){ $this-&amp;gt;redirect(\u2018mobile\/index\u2019); } } \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd52 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u628a\u65b9\u6cd5\u653e\u5728app\/common\u3002php\u6587\u4ef6\u5939\u91cc\u9762 \/\/&nbsp;\u5e94\u7528\u516c\u5171\u6587\u4ef6 \/\/\u5224\u65ad\u5ba2\u6237\u7aef\u8bbf\u95ee\u65b9\u5f0f function&nbsp;ismobile()&nbsp;{ \/\/&nbsp;\u5982\u679c\u6709HTTP_X_WAP_PROFILE\u5219\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907 if&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_X_WAP_PROFILE\u2019])) return&nbsp;true; \/\/\u6b64\u6761\u6458\u81eaTPM\u667a\u80fd\u5207\u6362\u6a21\u677f\u5f15\u64ce\uff0c\u9002\u5408TPM\u5f00\u53d1 if(isset&nbsp;($_SERVER[\u2018HTTP_CLIENT\u2019])&nbsp;&amp;amp;&amp;amp;\u2019PhoneClient\u2019==$_SERVER[\u2018HTTP_CLIENT\u2019]) return&nbsp;true; \/\/\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 if&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_VIA\u2019])) \/\/\u627e\u4e0d\u5230\u4e3aflase,\u5426\u5219\u4e3atrue return&nbsp;stristr($_SERVER[\u2018HTTP_VIA\u2019],&nbsp;\u2018wap\u2019)&nbsp;?&nbsp;true&nbsp;:&nbsp;false; \/\/\u5224\u65ad\u624b\u673a\u53d1\u9001\u7684\u5ba2\u6237\u7aef\u6807\u5fd7,\u517c\u5bb9\u6027\u6709\u5f85\u63d0\u9ad8 if&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_USER_AGENT\u2019]))&nbsp;{ $clientkeywords&nbsp;=&nbsp;array( \u2018nokia\u2019,\u2019sony\u2019,\u2019ericsson\u2019,\u2019mot\u2019,\u2019samsung\u2019,\u2019htc\u2019,\u2019sgh\u2019,\u2019lg\u2019,\u2019sharp\u2019,\u2019sie-\u2018,\u2019philips\u2019,\u2019panasonic\u2019,\u2019alcatel\u2019,\u2019lenovo\u2019,\u2019iphone\u2019,\u2019ipod\u2019,\u2019blackberry\u2019,\u2019meizu\u2019,\u2019android\u2019,\u2019netfront\u2019,\u2019symbian\u2019,\u2019ucweb\u2019,\u2019windowsce\u2019,\u2019palm\u2019,\u2019operamini\u2019,\u2019operamobi\u2019,\u2019openwave\u2019,\u2019nexusone\u2019,\u2019cldc\u2019,\u2019midp\u2019,\u2019wap\u2019,\u2019mobile\u2019 ); \/\/\u4eceHTTP_USER_AGENT\u4e2d\u67e5\u627e\u624b\u673a\u6d4f\u89c8\u5668\u7684\u5173\u952e\u5b57 if&nbsp;(preg_match(\u201c\/(\u201d&nbsp;.&nbsp;implode(\u2018|\u2019,&nbsp;$clientkeywords)&nbsp;.&nbsp;\u201c)\/i\u201d,&nbsp;strtolower($_SERVER[\u2018HTTP_USER_AGENT\u2019])))&nbsp;{ return&nbsp;true; } } \/\/\u534f\u8bae\u6cd5\uff0c\u56e0\u4e3a\u6709\u53ef\u80fd\u4e0d\u51c6\u786e\uff0c\u653e\u5230\u6700\u540e\u5224\u65ad if&nbsp;(isset&nbsp;($_SERVER[\u2018HTTP_ACCEPT\u2019]))&nbsp;{ \/\/&nbsp;\u5982\u679c\u53ea\u652f\u6301wml\u5e76\u4e14\u4e0d\u652f\u6301html\u90a3\u4e00\u5b9a\u662f\u79fb\u52a8\u8bbe\u5907 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-23189","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23189","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=23189"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23189\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}