{"id":31215,"date":"2024-11-25T16:59:54","date_gmt":"2024-11-25T08:59:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31215\/"},"modified":"2024-11-25T16:59:54","modified_gmt":"2024-11-25T08:59:54","slug":"phpcms%e5%88%a4%e6%96%ad%e6%98%af%e5%90%a6%e4%b8%ba%e6%89%8b%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31215\/","title":{"rendered":"phpcms\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a"},"content":{"rendered":"<p>\u6709\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5224\u65ad\u7528\u6237\u7684\u7ec8\u7aef\u7c7b\u578b\uff0c\u8fd4\u56de\u4e0d\u540c\u7684\u9875\u9762\u6548\u679c\uff0c\u6bd4\u5982\u624b\u673a\u548c\u7535\u8111\u8fd4\u56de\u4e0d\u540c\u7684url\u9875\u9762\uff0c\u90a3\u4e48\u5982\u4f55\u5224\u65ad\u5462\uff1f\u6211\u4eec\u4e00\u8d77\u6765\u5b66\u4e60\u4e00\u4e0b\u5427\uff01<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/040\/5e3a75824576f444.jpg\" class=\"aligncenter\" title=\"phpcms\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a\u63d2\u56fe\" alt=\"phpcms\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a\u63d2\u56fe\" \/><\/p>\n<p><strong>phpcms\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2aisMobile()\u65b9\u6cd5\uff0c\u7528\u6765\u5224\u65ad\u7528\u6237\u662f\u5426\u662f\u624b\u673a\u8bbf\u95ee\u3002<strong><br \/><\/strong><\/p>\n<pre>\/**\n&nbsp;*&nbsp;Function&nbsp;isMobile\n&nbsp;&nbsp;*&nbsp;@param&nbsp;$n&nbsp;\u5224\u65ad\u624b\u673a\u7248\n&nbsp;*\/\n&nbsp;function&nbsp;isMobile(){&nbsp;&nbsp;\n&nbsp;\t$useragent=isset($_SERVER['HTTP_USER_AGENT'])&nbsp;?&nbsp;$_SERVER['HTTP_USER_AGENT']&nbsp;:&nbsp;'';&nbsp;&nbsp;\n&nbsp;\t$useragent_commentsblock=preg_match('|(.*?)|',$useragent,$matches)&amp;gt;0?$matches[0]:'';&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\tfunction&nbsp;CheckSubstrs($substrs,$text){&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\tforeach($substrs&nbsp;as&nbsp;$substr)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\t\tif(false!==strpos($text,$substr)){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\t\t\treturn&nbsp;true;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\t\t}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\t\treturn&nbsp;false;&nbsp;&nbsp;\n&nbsp;\t\t}\n&nbsp;\t$mobile_os_list=array('Google&nbsp;Wireless&nbsp;Transcoder','Windows&nbsp;CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera&nbsp;Mobi','J2ME\/MIDP','Smartphone','Go.Web','Palm','iPAQ');\n&nbsp;\t$mobile_token_list=array('Profile\/MIDP','Configuration\/CLDC-','160\u00d7160','176\u00d7220','240\u00d7240','240\u00d7320','320\u00d7240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');&nbsp;&nbsp;\n&nbsp;\t$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock)&nbsp;||&nbsp;CheckSubstrs($mobile_token_list,$useragent);&nbsp;&nbsp;\n&nbsp;\tif&nbsp;($found_mobile){&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\treturn&nbsp;true;&nbsp;&nbsp;\n&nbsp;\t}else{&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\t\treturn&nbsp;false;&nbsp;&nbsp;\n&nbsp;\t}&nbsp;&nbsp;\n&nbsp;}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/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\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a\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>\u6709\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5224\u65ad\u7528\u6237\u7684\u7ec8\u7aef\u7c7b\u578b\uff0c\u8fd4\u56de\u4e0d\u540c\u7684\u9875\u9762\u6548\u679c\uff0c\u6bd4\u5982\u624b\u673a\u548c\u7535\u8111\u8fd4\u56de\u4e0d\u540c\u7684url\u9875\u9762\uff0c\u90a3\u4e48\u5982\u4f55\u5224\u65ad\u5462\uff1f\u6211\u4eec\u4e00\u8d77\u6765\u5b66\u4e60\u4e00\u4e0b\u5427\uff01 phpcms\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a \u521b\u5efa\u4e00\u4e2aisMobile()\u65b9\u6cd5\uff0c\u7528\u6765\u5224\u65ad\u7528\u6237\u662f\u5426\u662f\u624b\u673a\u8bbf\u95ee\u3002 \/** &nbsp;*&nbsp;Function&nbsp;isMobile &nbsp;&nbsp;*&nbsp;@param&nbsp;$n&nbsp;\u5224\u65ad\u624b\u673a\u7248 &nbsp;*\/ &nbsp;function&nbsp;isMobile(){&nbsp;&nbsp; &nbsp; $useragent=isset($_SERVER[&#8216;HTTP_USER_AGENT&#8217;])&nbsp;?&nbsp;$_SERVER[&#8216;HTTP_USER_AGENT&#8217;]&nbsp;:&nbsp;&#8221;;&nbsp;&nbsp; &nbsp; $useragent_commentsblock=preg_match(&#8216;|(.*?)|&#8217;,$useragent,$matches)&amp;gt;0?$matches[0]:&#8221;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; function&nbsp;CheckSubstrs($substrs,$text){&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; foreach($substrs&nbsp;as&nbsp;$substr)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if(false!==strpos($text,$substr)){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return&nbsp;true;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return&nbsp;false;&nbsp;&nbsp; &nbsp; } &nbsp; $mobile_os_list=array(&#8216;Google&nbsp;Wireless&nbsp;Transcoder&#8217;,&#8217;Windows&nbsp;CE&#8217;,&#8217;WindowsCE&#8217;,&#8217;Symbian&#8217;,&#8217;Android&#8217;,&#8217;armv6l&#8217;,&#8217;armv5&#8242;,&#8217;Mobile&#8217;,&#8217;CentOS&#8217;,&#8217;mowser&#8217;,&#8217;AvantGo&#8217;,&#8217;Opera&nbsp;Mobi&#8217;,&#8217;J2ME\/MIDP&#8217;,&#8217;Smartphone&#8217;,&#8217;Go.Web&#8217;,&#8217;Palm&#8217;,&#8217;iPAQ&#8217;); &nbsp; $mobile_token_list=array(&#8216;Profile\/MIDP&#8217;,&#8217;Configuration\/CLDC-&#8216;,&#8217;160\u00d7160&#8242;,&#8217;176\u00d7220&#8242;,&#8217;240\u00d7240&#8242;,&#8217;240\u00d7320&#8242;,&#8217;320\u00d7240&#8242;,&#8217;UP.Browser&#8217;,&#8217;UP.Link&#8217;,&#8217;SymbianOS&#8217;,&#8217;PalmOS&#8217;,&#8217;PocketPC&#8217;,&#8217;SonyEricsson&#8217;,&#8217;Nokia&#8217;,&#8217;BlackBerry&#8217;,&#8217;Vodafone&#8217;,&#8217;BenQ&#8217;,&#8217;Novarra-Vision&#8217;,&#8217;Iris&#8217;,&#8217;NetFront&#8217;,&#8217;HTC_&#8217;,&#8217;Xda_&#8217;,&#8217;SAMSUNG-SGH&#8217;,&#8217;Wapaka&#8217;,&#8217;DoCoMo&#8217;,&#8217;iPhone&#8217;,&#8217;iPod&#8217;);&nbsp;&nbsp; &nbsp; $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock)&nbsp;||&nbsp;CheckSubstrs($mobile_token_list,$useragent);&nbsp;&nbsp; &nbsp; if&nbsp;($found_mobile){&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return&nbsp;true;&nbsp;&nbsp; &nbsp; }else{&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return&nbsp;false;&nbsp;&nbsp; &nbsp; }&nbsp;&nbsp; &nbsp;} \u767b\u5f55\u540e\u590d\u5236 PHP\u4e2d\u6587\u7f51\uff0c\u5927\u91cf\u7684\u514d\u8d39\uff0c\u6b22\u8fce\u5728\u7ebf\u5b66\u4e60\uff01 \u4ee5\u4e0a\u5c31\u662f\u5224\u65ad\u662f\u5426\u4e3a\u624b\u673a\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-31215","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31215","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=31215"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31215\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}