{"id":1254,"date":"2026-01-06T16:03:51","date_gmt":"2026-01-06T08:03:51","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1254"},"modified":"2026-01-06T16:03:51","modified_gmt":"2026-01-06T08:03:51","slug":"php%e5%ae%9e%e7%8e%b0%e9%a1%b5%e9%9d%a2%e8%b7%b3%e8%bd%ac%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/01\/06\/php%e5%ae%9e%e7%8e%b0%e9%a1%b5%e9%9d%a2%e8%b7%b3%e8%bd%ac%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e5%bc%8f\/","title":{"rendered":"PHP\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\u7684\u4e09\u79cd\u65b9\u5f0f"},"content":{"rendered":"\n<p>\u5728 PHP \u4e2d\uff0c\u5b9e\u73b0<strong>\u9875\u9762\u8df3\u8f6c\uff08Redirect\uff09\u5e38\u89c1\u6709 3 \u79cd\u65b9\u5f0f\u3002\u4e0b\u9762\u6211\u6309\u4f7f\u7528\u9891\u7387 + \u5b9e\u9645\u573a\u666f<\/strong>\u7ed9\u4f60\u8bb2\u6e05\u695a\uff0c\u6bcf\u79cd\u90fd\u9644 <strong>\u53ef\u76f4\u63a5\u7528\u7684\u4ee3\u7801\u793a\u4f8b<\/strong> \ud83d\udc47<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u65b9\u5f0f\u4e00\uff1a<code>header()<\/code> \u8df3\u8f6c\uff08\u6700\u5e38\u7528 \u2705\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\u4ee3\u7801<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\nheader(&quot;Location: https:\/\/www.example.com&quot;);\nexit;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5e26\u72b6\u6001\u7801\uff08\u63a8\u8350\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nheader(&quot;Location: \/login.php&quot;, true, 302);\nexit;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5e38\u89c1\u72b6\u6001\u7801<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u72b6\u6001\u7801<\/th><th>\u542b\u4e49<\/th><\/tr><\/thead><tbody><tr><td>302<\/td><td>\u4e34\u65f6\u8df3\u8f6c\uff08\u9ed8\u8ba4\uff09<\/td><\/tr><tr><td>301<\/td><td>\u6c38\u4e45\u8df3\u8f6c\uff08SEO \u7528\uff09<\/td><\/tr><tr><td>303<\/td><td>POST \u540e\u8df3\u8f6c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nheader(&quot;Location: \/success.php&quot;, true, 303);\nexit;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879\uff08\u975e\u5e38\u91cd\u8981\uff09<\/h3>\n\n\n\n<p>\u2757 \u5fc5\u987b\u5728 <strong>\u4efb\u4f55\u8f93\u51fa\u4e4b\u524d<\/strong><br>\u2757 \u4e00\u5b9a\u8981 <code>exit<\/code><br>\u2757 \u4e0d\u9002\u7528\u4e8e\u5df2\u7ecf\u8f93\u51fa HTML \u7684\u60c5\u51b5<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u65b9\u5f0f\u4e8c\uff1aJavaScript \u8df3\u8f6c\uff08\u524d\u7aef\u8df3\u8f6c\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\u4ee3\u7801<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\necho &quot;&amp;lt;script&gt;window.location.href=&#039;https:\/\/www.example.com&#039;;&amp;lt;\/script&gt;&quot;;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5ef6\u65f6\u8df3\u8f6c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\necho &quot;&amp;lt;script&gt;\n    setTimeout(function(){\n        location.href = &#039;success.php&#039;;\n    }, 3000);\n&amp;lt;\/script&gt;&quot;;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u9002\u7528\u573a\u666f<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5df2\u7ecf\u8f93\u51fa\u9875\u9762<\/li>\n\n\n\n<li>\u9700\u8981\u63d0\u793a\u540e\u8df3\u8f6c<\/li>\n\n\n\n<li>\u7528\u6237\u53ef\u89c1\u7684\u4ea4\u4e92\u8df3\u8f6c<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u65b9\u5f0f\u4e09\uff1aHTML Meta Refresh \u8df3\u8f6c<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\u4ee3\u7801<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\necho &#039;&amp;lt;meta http-equiv=&quot;refresh&quot; content=&quot;0;url=success.php&quot;&gt;&#039;;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5ef6\u65f6\u8df3\u8f6c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\necho &#039;&amp;lt;meta http-equiv=&quot;refresh&quot; content=&quot;5;url=success.php&quot;&gt;&#039;;\necho &#039;5 \u79d2\u540e\u8df3\u8f6c...&#039;;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u4f18\u70b9<\/th><th>\u7f3a\u70b9<\/th><\/tr><\/thead><tbody><tr><td>\u7b80\u5355<\/td><td>SEO \u4e0d\u53cb\u597d<\/td><\/tr><tr><td>\u53ef\u5ef6\u65f6<\/td><td>\u7528\u6237\u4f53\u9a8c\u4e00\u822c<\/td><\/tr><tr><td>\u4e0d\u53d7 header \u9650\u5236<\/td><td>\u4f9d\u8d56\u6d4f\u89c8\u5668<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u4e09\u79cd\u65b9\u5f0f\u5bf9\u6bd4\uff08\u901f\u67e5\u8868\uff09<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u5f0f<\/th><th>\u662f\u5426\u63a8\u8350<\/th><th>\u9002\u5408\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td>header()<\/td><td>\u2b50\u2b50\u2b50\u2b50\u2b50<\/td><td>\u540e\u7aef\u903b\u8f91\u8df3\u8f6c<\/td><\/tr><tr><td>JavaScript<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><td>\u5df2\u8f93\u51fa\u9875\u9762<\/td><\/tr><tr><td>Meta Refresh<\/td><td>\u2b50\u2b50<\/td><td>\u515c\u5e95\u65b9\u6848<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5e38\u89c1\u9519\u8bef\uff08\u65b0\u4eba\u6700\u5bb9\u6613\u8e29\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u274c \u9519\u8bef 1\uff1aheader \u524d\u6709\u8f93\u51fa<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\necho &quot;hello&quot;;\nheader(&quot;Location: \/index.php&quot;); \/\/ \u65e0\u6548\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u274c \u9519\u8bef 2\uff1a\u5fd8\u8bb0 exit<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nheader(&quot;Location: \/index.php&quot;);\n\/\/ \u540e\u9762\u7684\u4ee3\u7801\u8fd8\u4f1a\u6267\u884c\uff01\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u5b9e\u6218\u793a\u4f8b\uff1a\u767b\u5f55\u5224\u65ad\u8df3\u8f6c<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nif (!isset($_SESSION&#x5B;&#039;user&#039;])) {\n    header(&quot;Location: login.php&quot;);\n    exit;\n}\n\necho &quot;\u6b22\u8fce\u767b\u5f55&quot;;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u4e00\u53e5\u8bdd\u603b\u7ed3<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u80fd\u7528 <code>header()<\/code> \u5c31\u7528 <code>header()<\/code>\uff1b\u5df2\u7ecf\u8f93\u51fa\u4e86\u5185\u5bb9\uff0c\u518d\u7528 JS \u6216 Meta<\/strong><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 PHP \u4e2d\uff0c\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\uff08Redirect\uff09\u5e38\u89c1\u6709 3 \u79cd\u65b9\u5f0f\u3002\u4e0b\u9762\u6211\u6309\u4f7f\u7528&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2026\/01\/06\/php%e5%ae%9e%e7%8e%b0%e9%a1%b5%e9%9d%a2%e8%b7%b3%e8%bd%ac%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e5%bc%8f\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1254","post","type-post","status-publish","format-standard","hentry","category-php"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1254"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1254\/revisions"}],"predecessor-version":[{"id":1255,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1254\/revisions\/1255"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}