如何检测嵌入“src”发出的 GET 请求?
有什么方法可以检测 PHP 中的 GET 请求是否是由浏览器中嵌入 src 发出的?
<img src="xxxxx.php">
我尝试使用“REFFER”,但这不是一个好的解决方案。
我对http了解不多,但也许如果浏览器使用标签,它会发送标头接受图像或类似的东西,我可以在php中读取什么?
我只想创建脚本,如果嵌入,将显示图片,但如果以正常方式在浏览器中打开,例如 url,它会将用户重定向到其他页面。
Is there any way to detect in PHP is GET request made by embed src in browser?
<img src="xxxxx.php">
I was trying use "REFFER", but it's very not good solution.
I don't know lot about http, but maybe if browser use tag, it send header accept image or anything like this what i can read in php ?
I just want create script what will display picture if embed, but if open in browser in normal way, like url it will redirect user to other page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不。
No.
如果您将文件隐藏在根目录之外的文件夹中,请创建一个所有图像都通过的 PHP 文件 (
image.php?lovely_duck.jpg
),然后查找$_SERVER['HTTP_REFERER' ]
,这是可能的。但是您可以伪造$_SERVER['HTTP_REFERER']
和 它并不总是可靠的。如果您试图找到一种方法来阻止人们获取您的图像,他们总会找到方法。
If you hide your files in a folder outside the root, created a PHP file that all images routed through (
image.php?lovely_duck.jpg
) and then looked for$_SERVER['HTTP_REFERER']
, that would be possible. But you can forge$_SERVER['HTTP_REFERER']
and it isn’t always reliable.If you’re trying to find a way to stopping people getting your images, they’ll always find a way.
您可以(但我不建议这样做)检查
Accept
标头。如果请求是由
触发的,则不应包含“text/html”。
还描述了此处
但再说一遍:我不建议使用它。< br>
目前这将破坏 Firefox 和可能的其他浏览器中的下载图像功能。
此外,它不会阻止“邪恶的家伙”下载您的所有图像,因为他们只需设置所需的 HTTP 标头即可。
You can (but i would NOT suggest it) check the
Accept
header.If the request was triggered by an
<img src=...
it should NOT contain "text/html".Also described here
But again: i would not suggest using this.
At the moment that will break the download image functionality in firefox and possible other browser.
Additionally it won't prevent "evil guys" to download all your images because they simply can set the required HTTP header.