如何防止直接URL访问?
请帮助我解决热链接问题,如何防止直接访问此 URL 并将访问者重定向到 index.php:
http://www.example.com/index.php?link=http://www.anysite.com/dir/file&name=on&email=on&submit=on
Please help me to resolve hotlinking, how to prevent direct access to this URL and redirect visitors to index.php:
http://www.example.com/index.php?link=http://www.anysite.com/dir/file&name=on&email=on&submit=on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你在寻找这样的东西吗:
are you searching for something like this:
为了回答这个问题,我假设您不关心同一用户是否访问
多次(前提是第一次访问来自主索引页面)。这也假设用户将接受 cookie。
在主索引页面上时:
加载时url:
如果不存在则设置参数,
将它们重定向回主索引
页。或者更有帮助的是,既然你正在创造一种奇怪的行为,那就向他们展示
一条错误消息,指示您正在做什么以及为什么。
会话并确保该值
在他们的会话中匹配该值
在网址中。
For purposes of answering this, I'm going to assume you don't care if the same user accesses
it multiple times (provided that the first visit came through the main index page). This also assumes the user will accept a cookies.
When on the main index page:
When loading a url:
param is set if it isn't there,
redirect them back to main index
page. Or more helpfully, since you are creating a weird behavior, show them
a error message indicating what you are doing, and why.
session and make sure that the value
in their session matches the value
in the url.
使用 htaccess 文件是解决此问题的常见方法:
来自 http://altlab.com/htaccess_tutorial.html
该代码特别会重定向任何试图热链接图像的人。
Using an htaccess file is a common solution to this problem:
from http://altlab.com/htaccess_tutorial.html
This code in particular redirects anyone trying to hotlink an image.