在 PHP 中设置 Referer 的替代 Header() 命令?

发布于 2024-09-09 08:26:29 字数 253 浏览 9 评论 0原文

我试图从服务器启动下载,除非将引荐来源网址设置为相同的域,否则将出现 403 禁止。目前 Header() 允许我将用户重定向到文件位置并启动下载,但引用者始终设置为我的脚本。使用curl 会导致文件下载到服务器端。谁能帮我找到一种解决方法来重定向用户,同时设置引荐来源网址???

示例代码片段:

header("Location: $filelocation"); # Need to set Referer = $url

I am trying to initiate a download from a server that will give a 403 forbidden unless the referrer is set to the same domain. Currently Header() allows me to redirect the user to the file location and init a download, but referrer is always set to my script. Use of curl would cause the file to download on the server side. Can anyone help me find a work around to redirect the user while also setting the referrer???

Example code snippet:

header("Location: $filelocation"); # Need to set Referer = $url

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是偏爱你 2024-09-16 08:26:29

Referer,或者通常任何请求标头,始终由请求方设置。您的服务器(即响应方)无法强制客户端(浏览器)为请求设置任何特定标头。发送什么标头完全取决于浏览器。

您唯一能做的就是通过 cURL 下载图像,伪造任何您想要的标头(因为您是请求方)并将图像从服务器输出到客户端(基本上充当代理人)。听起来你正在做一些你确实不应该做的事情,所以我将让你自己解决这个问题。

The Referer, or generally any request header, is always set by the requesting party. Your server, which is the responding party, cannot force the client (browser) to set any specific header for a request. It's completely up to the browser what headers to send.

The only thing you could do is to download the image via cURL, faking any header you want (because you're the requesting party) and output the image from your server to the client (basically acting as a proxy). It sounds like you're doing something you're really not supposed to though, so I'll leave it up to you to figure that out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文