{"id":46826,"date":"2024-12-02T15:22:22","date_gmt":"2024-12-02T07:22:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46826\/"},"modified":"2024-12-02T15:22:22","modified_gmt":"2024-12-02T07:22:22","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8%e5%91%bd%e4%bb%a4%e8%a1%8c%e7%a8%8b%e5%ba%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46826\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>PHP \u53ef\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1aexec() \u51fd\u6570\uff1a\u6267\u884c\u547d\u4ee4\u5e76\u8fd4\u56de\u8f93\u51fa\uff0c\u4f46\u4e0d\u4f1a\u6253\u5370\u3002shell_exec() \u51fd\u6570\uff1a\u6267\u884c\u547d\u4ee4\uff0c\u8fd4\u56de\u5e76\u6253\u5370\u8f93\u51fa\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729849007671b66af919f6.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f<\/h2>\n<p>\u5728 PHP \u4e2d\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\u9700\u8981\u7528\u5230 <code>exec()<\/code> \u6216 <code>shell_exec()<\/code> \u51fd\u6570\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u5141\u8bb8\u60a8\u6267\u884c\u5916\u90e8\u547d\u4ee4\u5e76\u8fd4\u56de\u7ed3\u679c\u6216\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u6253\u5370\u5728\u9875\u9762\u4e0a\u3002<\/p>\n<h3><code>exec()<\/code> \u51fd\u6570<\/h3>\n<p><code>exec()<\/code> \u51fd\u6570\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u5e76\u8fd4\u56de\u5176\u8f93\u51fa\u4f5c\u4e3a\u5b57\u7b26\u4e32\u3002\u4f46\u662f\uff0c\u5b83\u4e0d\u80fd\u6253\u5370\u8f93\u51fa\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>exec($command, &amp;$output, &amp;$return_var);<\/pre>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li><code>$command<\/code>\uff1a\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/li>\n<li><code>&amp;$output<\/code>\uff08\u53ef\u9009\uff09\uff1a\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7684\u53d8\u91cf\uff0c\u5b83\u63a5\u6536\u547d\u4ee4\u7684\u8f93\u51fa\u3002<\/li>\n<li><code>&amp;$return_var<\/code>\uff08\u53ef\u9009\uff09\uff1a\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7684\u53d8\u91cf\uff0c\u5b83\u63a5\u6536\u8fd4\u56de\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<p><strong>\u8303\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;?php\nexec('ls -la', $output);\nprint_r($output);\n?&gt;<\/pre>\n<h3><code>shell_exec()<\/code> \u51fd\u6570<\/h3>\n<p><code>shell_exec()<\/code> \u51fd\u6570\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u5e76\u8fd4\u56de\u5176\u8f93\u51fa\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff0c\u5e76\u4e14\u4e5f\u4f1a\u6253\u5370\u8f93\u51fa\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>shell_exec($command);<\/pre>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li><code>$command<\/code>\uff1a\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<p><strong>\u8303\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;?php\n$output = shell_exec('ls -la');\necho $output;\n?&gt;<\/pre>\n<h3>\u5b9e\u6218\u6848\u4f8b<\/h3>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a <code>test.txt<\/code> \u7684\u6587\u4ef6\uff0c\u60a8\u5e0c\u671b\u4f7f\u7528 PHP \u6253\u5370\u5176\u5185\u5bb9\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;?php\n$output = shell_exec('cat test.txt');\necho $output;\n?&gt;<\/pre>\n<h3>\u6ce8\u610f<\/h3>\n<ul>\n<li>\u4f7f\u7528 <code>exec()<\/code> \u548c <code>shell_exec()<\/code> \u51fd\u6570\u65f6\uff0c\u9700\u8981\u8c28\u614e\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u4e0a\u6267\u884c\u4efb\u610f\u547d\u4ee4\u3002<\/li>\n<li>\u786e\u4fdd\u547d\u4ee4\u4e2d\u6ca1\u6709\u6076\u610f\u4ee3\u7801\u6216\u6267\u884c\u4e0d\u5fc5\u8981\u64cd\u4f5c\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528\u66f4\u5b89\u5168\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u5982 <code>popen()<\/code> \u6216 <code>proc_open()<\/code> \u51fd\u6570\uff0c\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u5916\u90e8\u7a0b\u5e8f\u7684\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300aPHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 PHP \u53ef\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1aexec() \u51fd\u6570\uff1a\u6267\u884c\u547d\u4ee4\u5e76\u8fd4\u56de\u8f93\u51fa\uff0c\u4f46\u4e0d\u4f1a\u6253\u5370\u3002shell_exec() \u51fd\u6570\uff1a\u6267\u884c\u547d\u4ee4\uff0c\u8fd4\u56de\u5e76\u6253\u5370\u8f93\u51fa\u3002 PHP \u51fd\u6570\u5982\u4f55\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\uff1f \u5728 PHP \u4e2d\u8c03\u7528\u547d\u4ee4\u884c\u7a0b\u5e8f\u9700\u8981\u7528\u5230 exec() \u6216 shell_exec() \u51fd\u6570\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u5141\u8bb8\u60a8\u6267\u884c\u5916\u90e8\u547d\u4ee4\u5e76\u8fd4\u56de\u7ed3\u679c\u6216\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u6253\u5370\u5728\u9875\u9762\u4e0a\u3002 exec() \u51fd\u6570 exec() \u51fd\u6570\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u5e76\u8fd4\u56de\u5176\u8f93\u51fa\u4f5c\u4e3a\u5b57\u7b26\u4e32\u3002\u4f46\u662f\uff0c\u5b83\u4e0d\u80fd\u6253\u5370\u8f93\u51fa\u3002 \u8bed\u6cd5\uff1a exec($command, &amp;$output, &amp;$return_var); \u53c2\u6570\uff1a $command\uff1a\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002 &amp;$output\uff08\u53ef\u9009\uff09\uff1a\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7684\u53d8\u91cf\uff0c\u5b83\u63a5\u6536\u547d\u4ee4\u7684\u8f93\u51fa\u3002 &amp;$return_var\uff08\u53ef\u9009\uff09\uff1a\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7684\u53d8\u91cf\uff0c\u5b83\u63a5\u6536\u8fd4\u56de\u4ee3\u7801\u3002 \u8303\u4f8b\uff1a &lt;?php exec(&#8216;ls -la&#8217;, $output); print_r($output); ?&gt; shell_exec() \u51fd\u6570 shell_exec() \u51fd\u6570\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u5e76\u8fd4\u56de\u5176\u8f93\u51fa\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff0c\u5e76\u4e14\u4e5f\u4f1a\u6253\u5370\u8f93\u51fa\u3002 \u8bed\u6cd5\uff1a shell_exec($command); \u53c2\u6570\uff1a $command\uff1a\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002 \u8303\u4f8b\uff1a &lt;?php $output = shell_exec(&#8216;ls -la&#8217;); echo $output; ?&gt; \u5b9e\u6218\u6848\u4f8b \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a [&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-46826","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46826","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=46826"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46826\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}