简体   繁体   English

仅限登录用户 PHP 访问文档/附件

[英]Restrict Access to Documents/Attachements only to Logged in User PHP

I have an application build in core PHP, I have one scenario where I got stuck.我在核心 PHP 中有一个应用程序构建,我有一个卡住的场景。 I have a company database, where the company's information and its related documents exist.我有一个公司数据库,其中存在公司的信息及其相关文件。 I want to show documents only to logged in user, currently if logged in user share link of documents with any other user they can access those documents without any login, which needs to be restricted.我只想向登录用户显示文档,目前如果登录用户与任何其他用户共享文档链接,他们无需任何登录即可访问这些文档,这需要受到限制。

Base Path is like that: abc.com/app and the path of the document are like that: abc.com/app/documents/random_company_name/all_documents_in_it.基本路径是这样的:abc.com/app 和文档的路径是这样的:abc.com/app/documents/random_company_name/all_documents_in_it。 random_company_name is a dynamically generated folder. random_company_name是一个动态生成的文件夹。

As documents path is directly going to access documents, no inclusion of any PHP script exists that's why I am stuck?由于文档路径将直接访问文档,因此不包含任何 PHP 脚本,这就是我被卡住的原因?

Can anybody have an idea how can I redirect that user to the login page and after login, I will check if the user belongs to the same company then access given else not?任何人都可以知道如何将该用户重定向到登录页面,登录后,我将检查用户是否属于同一家公司,然后访问是否给定?

I have tried using htaccess to redirect it to the authentication page if pdf opened but unable to handle images in it below is my code for htaccess?如果 pdf 打开但无法处理其中的图像,我尝试使用 htaccess 将其重定向到身份验证页面,下面是我的 htaccess 代码吗?

 #htaccess start
 RewriteEngine On
 RewriteRule !^((.pdf|.jpeg|.jpg)|(.*\/))$ authorizeacess.php

If I were you, I'll try to implement a middleware, with a http client like Guzzle .如果我是你,我会尝试使用像Guzzle这样的 http 客户端来实现一个中间件。 Then you could easily protect your files from being accessed with a link.然后,您可以轻松地保护您的文件不被链接访问。

As for the.htacess configuration, please check this answer about password protecting and this one about deny from all .至于 .htacess 配置,请查看这个关于密码保护的答案这个关于拒绝所有的答案。

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

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