{"id":1545,"date":"2023-03-25T15:29:37","date_gmt":"2023-03-25T07:29:37","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1545"},"modified":"2023-04-27T21:39:28","modified_gmt":"2023-04-27T13:39:28","slug":"changes-in-http-referer-during-multiple-redirects","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/changes-in-http-referer-during-multiple-redirects\/","title":{"rendered":"\u591a\u6b21\u91cd\u5b9a\u5411\u4e2dhttp-referer\u7684\u53d8\u5316"},"content":{"rendered":"<h2>\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u5148\u521d\u6b65\u4e86\u89e3\u4e0bURL\u91cd\u5b9a\u5411\uff0cHttp Referer\u4e24\u4e2a\u6982\u5ff5<\/p>\n<blockquote>\n<p>URL\u91cd\u5b9a\u5411\uff08URL redirection\uff0c\u6216\u79f0\u7f51\u5740\u91cd\u5b9a\u5411\u6216\u7f51\u57df\u540d\u79f0\u8f6c\u5740\uff09\uff0c\u662f\u6307\u5f53\u4f7f\u7528\u8005\u6d4f\u89c8\u67d0\u4e2a\u7f51\u5740\u65f6\uff0c\u5c06\u4ed6\u5bfc\u5411\u5230\u53e6\u4e00\u4e2a\u7f51\u5740\u7684\u6280\u672f\u3002<\/p>\n<\/blockquote>\n<p><!-- more --><\/p>\n<p>\u8bf4\u767d\u4e86\u5c31\u662fURL\u91cd\u5b9a\u5411\u5c31\u662f\u628a\u4e00\u4e2aURL\u91cd\u65b0\u5b9a\u5411\u5230\u53e6\u4e00\u4e2aURL\u4e0a\u53bb\uff0c\u91cd\u5b9a\u5411\u53ef\u4ee5\u628a\u4e00\u4e2a\u76ee\u5f55\u6216\u8005\u6587\u4ef6\u7684\u8bbf\u95ee\u8bf7\u6c42\u8f6c\u53d1\u81f3\u53e6\u5916\u4e00\u4e2a\u76ee\u5f55\u6216\u8005\u6587\u4ef6\u3002<\/p>\n<blockquote>\n<p>HTTP Referer\u662fheader\u7684\u4e00\u90e8\u5206\uff0c\u5f53\u6d4f\u89c8\u5668\u5411web\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\u7684\u65f6\u5019\uff0c\u4e00\u822c\u4f1a\u5e26\u4e0aReferer\uff0c\u544a\u8bc9\u670d\u52a1\u5668\u6211\u662f\u4ece\u54ea\u4e2a\u9875\u9762\u94fe\u63a5\u8fc7\u6765\u7684\uff0c\u670d\u52a1\u5668\u7c4d\u6b64\u53ef\u4ee5\u83b7\u5f97\u4e00\u4e9b\u4fe1\u606f\u7528\u4e8e\u5904\u7406\u3002<\/p>\n<\/blockquote>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bd4\u5982\u4ece\u767e\u5ea6\u641c\u7d22\u627e\u5230\u8fd9\u7bc7\u6587\u7ae0\u540e\uff0c\u7528\u6237\u70b9\u51fb\u8bbf\u95ee\u5230\u8fd9\u7bc7\u6587\u7ae0\uff0c\u90a3\u4e48\u6211\u5c31\u80fd\u591f\u4eceHTTP Referer\u4e2d\u7edf\u8ba1\u51fa\u6bcf\u5929\u6709\u591a\u5c11\u7528\u6237\u8bbf\u95ee\u6211\u8fd9\u4e2a\u9875\u9762\u6765\u81ea\u4e8e\u767e\u5ea6\u3002<\/p>\n<h2>HTTP Referer \u83b7\u53d6<\/h2>\n<p>\u5728ASP\u4e2d\u83b7\u53d6<code>Referer<\/code>\u7684\u65b9\u5f0f\u662f\uff1a<code>Request.ServerVariables(&quot;HTTP_REFERER&quot;);<\/code><br \/>\n\u5728JSP\u4e2d\u83b7\u53d6<code>Referer<\/code>\u7684\u65b9\u5f0f\u662f\uff1a<code>request.getHeader(&quot;REFERER&quot;);<\/code><br \/>\n\u5728PHP\u4e2d\u83b7\u53d6<code>Referer<\/code>\u7684\u65b9\u5f0f\u662f\uff1a<code>$_SERVER[&#039;HTTP_REFERER&#039;];<\/code><\/p>\n<p>\u4e0b\u5217\u60c5\u51b5\u662f\u80fd\u53d6\u5f97\u5230<code>Referer<\/code>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528<code>a<\/code>\u6807\u7b7e\u8bbf\u95ee\u9875\u9762<code>&lt;a href=&quot;http:\/\/www.appblog.cn\/&quot;&gt;\u70b9\u51fb\u8fd9\u91cc&lt;\/a&gt;<\/code><\/li>\n<li>\u4f7f\u7528JavaScript\u70b9\u51fb\u4e8b\u4ef6\u8bbf\u95ee\u9875\u9762<code>&lt;a href=&quot;#&quot; onclick=&#039;window.location.href=&quot;referer.php&quot;;return false;&#039;&gt;\u70b9\u51fb\u8fd9\u91cc&lt;\/a&gt;<\/code><\/li>\n<li>\u7528Submit input\u63d0\u4ea4\u7684\u8868\u5355(POST or GET)<\/li>\n<li>\u4f7f\u7528JavaScript\u63d0\u4ea4\u7684\u8868\u5355(POST or GET)\uff0c\u5176\u5b9e\u4e0e2\u7c7b\u4f3c\u3002<\/li>\n<li>\u4f7f\u7528JavaScript\u91cd\u5b9a\u5411\uff1a<code>location.href<\/code><\/li>\n<\/ul>\n<p>\u91cd\u70b9\u662f\u8fd9\u4e2a\uff0c\u4e0b\u5217\u60c5\u51b5\u662f\u53d6\u4e0d\u5230<code>Referer<\/code>\uff1a<\/p>\n<ul>\n<li>\u4ece\u6536\u85cf\u5939\u70b9\u51fb\u94fe\u63a5\uff0c\u6d4f\u89c8\u5668\u81ea\u5b9a\u4e49\u4e3b\u9875\u6253\u5f00\u6216\u662f\u5728\u6d4f\u89c8\u5668\u4e0a\u624b\u52a8\u8f93\u5165http\u5730\u5740<\/li>\n<li>\u4f7f\u7528\u670d\u52a1\u5668\u8bed\u8a00\u91cd\u5b9a\u5411\uff0c\u5982<code>ASP: Response.Redirect<\/code> <code>PHP: header(&#039;Location: &#039;)<\/code><\/li>\n<li>\u4f7f\u7528HTTP\u91cd\u5b9a\u5411\u65b9\u5f0f\uff0c\u5982302\u91cd\u5b9a\u5411<\/li>\n<li>\u4f7f\u7528JavaScript\u91cd\u5b9a\u5411\uff1a<code>location.replace()<\/code><\/li>\n<li>\u7528XML\u52a0\u8f7d\u5730\u5740<\/li>\n<\/ul>\n<h2>HTTP Referer \u4f20\u9012<\/h2>\n<p>\u5173\u4e8e\u4e8c\u6b21\u4ee5\u4e0a\u91cd\u5b9a\u5411\uff0c\u4fdd\u5b58<code>Referer<\/code>\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u4e3e\u4e00\u4e2a\u4f8b\u5b50\uff0c\u5018\u82e5\u6211\u4eec\u7684\u4e00\u4e2a\u94fe\u63a5\u5df2\u7ecf\u88ab\u767e\u5ea6\u6216\u8005\u8c37\u6b4c\u6536\u5f55\u4e86\uff0c\u5982\uff1a<br \/>\n<code>http:\/\/www.baidu.com\/s?wd=appblog.cn<\/code> \u8bb0\u4e3a\uff1a<strong>\u641c\u7d22\u9875<\/strong><\/p>\n<p>\u627e\u5230\u4e00\u6761\u81ea\u5df1\u7f51\u7ad9\u7684\u9875\u9762<br \/>\n<code>http:\/\/www.appblog.cn\/shopping.php<\/code> \u8bb0\u4e3a\uff1a<strong>\u9875\u9762A<\/strong><\/p>\n<p>\u800c\u6b64\u65f6\u6211\u4eec\u8fd9\u4e2a\u9875\u9762\u53ef\u80fd\u5df2\u7ecf\u4e0d\u9700\u8981\u4e86\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u9700\u8981\u91cd\u5b9a\u5411\u5230\u6211\u4eec\u7684\u4e00\u4e2a\u6dd8\u5b9d\u4e3b\u9875\uff1a\u5982\uff1a<br \/>\n<code>http:\/\/me1.taobao.com\/<\/code> \u8bb0\u4e3a\uff1a<strong>\u9875\u9762B<\/strong><\/p>\n<p>\u4e0a\u8ff0\u8fc7\u7a0b\u53ef\u4ee5\u770b\u505a\u4e3a\u4e8c\u6b21\u91cd\u5b9a\u5411\u3002<\/p>\n<p>\u6839\u636e\u4e0a\u9762\u6240\u8bf4\u7684\u60c5\u51b5\uff0c\u5728<strong>\u9875\u9762A<\/strong>\u662f\u53ef\u4ee5\u627e\u5230<code>Referer<\/code>\uff0c\u8fd9\u4e2a<code>Referer<\/code>\u5c31\u662f<strong>\u641c\u7d22\u9875<\/strong>\uff0c\u5f53\u91cd\u5b9a\u5411\u5230\u9875\u9762B\u4e0a\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0<strong>\u9875\u9762B<\/strong>\u5f97\u5230\u7684<code>Referer<\/code>\u5176\u5b9e\u4e5f\u662f<strong>\u641c\u7d22\u9875<\/strong>\u3002<\/p>\n<p>\u5bf9\u6b64\u627e\u5230\u7684\u89e3\u91ca\u4e3a\uff1a\u5927\u90e8\u5206\u6d4f\u89c8\u5668\u7684\u884c\u4e3a\u3002<\/p>\n<p>\u4f46\u6839\u636e\u4e0a\u8ff0<code>Referer<\/code>\u4e0d\u80fd\u83b7\u53d6\u7684\u60c5\u5f62\uff0c\u5982 HTTP 302 \u91cd\u5b9a\u5411\u65b9\u5f0f\u5c31\u65e0\u6cd5\u83b7\u53d6\u5230<code>Referer<\/code>\uff0c\u53c2\u8003\uff1a<\/p>\n<blockquote>\n<p><a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/stackoverflow.com\/questions\/2158283\/will-a-302-redirect-maintain-the-referer-string\">http:\/\/stackoverflow.com\/questions\/2158283\/will-a-302-redirect-maintain-the-referer-string<\/a><\/p>\n<\/blockquote>\n<p>\u56e0\u6b64\u4e0d\u80fd\u8fc7\u5206\u7684\u4f9d\u8d56<code>Referer<\/code>\uff0c\u5982\u8981\u6b63\u786e\u7684\u83b7\u5f97\u8fd9\u4e2a<code>Referer<\/code>\uff0c\u53ef\u4ee5\u5728\u9875\u9762A\u4e2d\u628a<code>Referer<\/code>\u4f5c\u4e3a\u53c2\u6570\uff0c\u4ece\u5730\u5740\u680f\u4e2d\u4f20\u9012\u5230\u4e0b\u4e2a\u9762\u3002\u5982<\/p>\n<pre><code class=\"language-php\">$url = &#039;http:\/\/&#039;.$_SERVER[&#039;HTTP_HOST&#039;].$_SERVER[&#039;REQUEST_URI&#039;];\n$url = base64_encode($url);\nheader (&#039;Location: http:\/\/www.taobao.com\/?referer=&#039;.$url);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u6982\u5ff5 \u5148\u521d\u6b65\u4e86\u89e3\u4e0bURL\u91cd\u5b9a\u5411\uff0cHttp Referer\u4e24\u4e2a\u6982\u5ff5 URL\u91cd\u5b9a\u5411\uff08URL redirecti [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[384],"class_list":["post-1545","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-referer"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1545"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1545\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}