简体   繁体   English

如何只允许登录用户访问图像

[英]How to only allow images to be accessed by logged in users

Currently using Codeigniter/PHP and IIS 7目前使用 Codeigniter/PHP 和 IIS 7

I have currently looked at "hotlinking" but that only protects images from being put onto other web sites.我目前正在研究“盗链”,但这只能保护图像不被放到其他网站上。 It doesn't stop the end user from directly pasting the image URL into the address bar and accessing the image whilst not being logged in.它不会阻止最终用户将图像 URL 直接粘贴到地址栏中并在未登录的情况下访问图像。

I am not too sure what the best way is to approach this problem.我不太确定解决这个问题的最佳方法是什么。 How can you protect images so that it can only be accessed by logged in users?您如何保护图像以使其只能由登录用户访问?

Thank you.谢谢你。

Put the images somewhere outside the webroot of the site.将图像放在网站 webroot之外的某个位置。

Have a php script that gets the images and displays the images only when logged in.有一个获取图像并在登录时显示图像的 php 脚本。

Best approach would be, if you stop using real url of images on the whole site and always retrieve the images via a php script(controller function) that could help you checking user authentication and other staffs like resize/crop/cache etc as well.最好的方法是,如果您停止在整个站点上使用图像的真实 url 并始终通过 php 脚本(控制器函数)检索图像,该脚本可以帮助您检查用户身份验证和其他人员(如调整大小/裁剪/缓存等)。

In that case, you can use any url even in root base, which isn't known to outside world at all.在这种情况下,您甚至可以在根基中使用任何 url,这是外界根本不知道的。

There are perfomance issues in the above answer.上面的回答有性能问题。 You can rename the folder that containing images every hour / day .... Ex您可以每小时/每天重命名包含图像的文件夹......例如

images/a8s7d5r7w9/33229.png to images/g2j3s3l1p2t/33229.png images/a8s7d5r7w9/33229.pngimages/g2j3s3l1p2t/33229.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM