{"id":285,"date":"2021-07-16T15:31:00","date_gmt":"2021-07-16T07:31:00","guid":{"rendered":"https:\/\/cn1.club\/?p=285"},"modified":"2025-03-15T23:20:04","modified_gmt":"2025-03-15T15:20:04","slug":"php%e6%af%8f%e6%ac%a1%e5%88%b7%e6%96%b0%e9%83%bd%e6%98%be%e7%a4%ba%e9%9a%8f%e6%9c%ba%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/cn1.club\/?p=285","title":{"rendered":"[PHP]\u6bcf\u6b21\u5237\u65b0\u90fd\u663e\u793a\u968f\u673a\u56fe\u7247"},"content":{"rendered":"\n<p>\u4ee3\u7801:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\n&lt;?php\n\n$device = $_GET&#091;&#039;device&#039;];\/\/\u8bbe\u5907\n\n\nif($device == null || $device == &#039;auto&#039; || $device == &#039;AUTO&#039;){\n    if(wp_is_mobile() == true){\n        $img_array = glob(&quot;Store\/Pe\/*.{gif,jpg,png}&quot;,GLOB_BRACE); \n    }else{\n        $img_array = glob(&quot;Store\/Pc\/*.{gif,jpg,png}&quot;,GLOB_BRACE); \n    }\n}else{\n    if($device == &#039;pc&#039; || $device == &#039;Pc&#039; || $device == &#039;PC&#039;){\n         $img_array = glob(&quot;Store\/Pc\/*.{gif,jpg,png}&quot;,GLOB_BRACE); \n    }else if($device == &#039;pe&#039; || $device == &#039;Pe&#039; || $device == &#039;PE&#039;){\n         $img_array = glob(&quot;Store\/Pe\/*.{gif,jpg,png}&quot;,GLOB_BRACE); \n    }else{\n         $img_array = glob(&quot;Store\/Pc\/*.{gif,jpg,png}&quot;,GLOB_BRACE);\n    }\n\n}\n\n$img = array_rand($img_array); \nheader(&quot;Location:&quot;.$img_array&#091;$img]);\n\n\/\/\u5224\u65ad\u624b\u673a\u6216\u8005\u7535\u8111\nfunction wp_is_mobile() {\n static $is_mobile = null;\n \n if ( isset( $is_mobile ) ) {\n  return $is_mobile;\n }\n \n if ( empty($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;]) ) {\n  $is_mobile = false;\n } elseif ( strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;Mobile&#039;) !== false \/\/ many mobile devices (all iPhone, iPad, etc.)\n  || strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;Android&#039;) !== false\n  || strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;Silk\/&#039;) !== false\n  || strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;Kindle&#039;) !== false\n  || strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;BlackBerry&#039;) !== false\n  || strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;Opera Mini&#039;) !== false\n  || strpos($_SERVER&#091;&#039;HTTP_USER_AGENT&#039;], &#039;Opera Mobi&#039;) !== false ) {\n   $is_mobile = true;\n } else {\n  $is_mobile = false;\n }\n \n return $is_mobile;\n}\n?&gt;<\/code><\/pre>\n\n\n\n<p>\u5c06\u4ee5\u4e0a\u4ee3\u7801\u4fdd\u5b58\u5230\u7f51\u7ad9\u6839\u76ee\u5f55\u547d\u540d\u4e3aapi.php\u5e76\u5728\u6839\u76ee\u5f55\u521b\u5efa\u4e00\u4e2aStore\u6587\u4ef6\u5939\u91cc\u9762\u542b\u6709Pc\u548cPe\u7684\u5b50\u6587\u4ef6\u5939\u5373\u53ef.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801: \u5c06\u4ee5\u4e0a\u4ee3\u7801\u4fdd\u5b58\u5230\u7f51\u7ad9\u6839\u76ee\u5f55\u547d\u540d\u4e3aapi.php\u5e76\u5728\u6839\u76ee\u5f55\u521b\u5efa\u4e00\u4e2aStore\u6587\u4ef6\u5939\u91cc\u9762\u542b\u6709Pc\u548cPe\u7684\u5b50 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"class_list":["post-285","post","type-post","status-publish","format-standard","hentry","category-zuopin"],"_links":{"self":[{"href":"https:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=285"}],"version-history":[{"count":0,"href":"https:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/285\/revisions"}],"wp:attachment":[{"href":"https:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}