应用的.htaccess文件夹的用户名/密码,使用PHP文件夹、用户名、密码、htaccess

2023-09-02 10:03:12 作者:相顾无言

我要建一个PHP / MySQL的Web应用程序。用户登录和各种会话变量设置。

I’m building a PHP/MySQL web application. Users log in and various session variables are set.

有上,用户可以将文件上传到(任何形式 - 图像,PDF,名为.doc等)Web服务器的文件夹。我想,以保护这个文件夹prevent人们还没有登录输入的URL和获得这些文件谁。文件的此文件夹中浏览是不允许的。

There’s a folder on the webserver where users can upload files to (any kind – images, pdf, .doc etc). I’d like to protect this folder to prevent people who are not logged in typing in the url and getting to these files. Browsing of files in this folder is disallowed.

我可以用我的cPanel,这很好地工作申请一个密码。然而,这意味着用户必须登录到应用程序,然后他们第一次浏览到某个文件在这个保护的文件夹,它们提示输入用户名/密码保护的文件夹中。我想使它所以他们没有为受保护的文件夹中的用户名/密码输入。

I can apply a password using my cpanel, which works nicely. However it means that users have to log in to the application, then the first time they navigate to a file in this protected folder, they’re prompted for the username/password for the protected folder. I’d like to make it so they don’t have to type in the username/password for the protected folder.

有没有什么办法,当用户登录时,设置他们的会话变量,在那个同一时间 - 使用PHP - 还可以设置用户名/密码保护的文件夹 - 所以你不提示他们? 谢谢。伊恩。

Is there any way when a user logs in, setting their session variables, to at that same time – using PHP – also set the username/password for the protected folder – so they’re not prompted? Thank you. Iain.

推荐答案

我已经做了这几年来,但它的工作非常好,的cPanel:我编程叫的cPanel的目录保护设置页面,并添加用户名/密码有。所以的cPanel了服务器管理的照顾。但是我不知道是否仍然有效。

I've did this years ago, but it worked very well with cpanel: I programmatically called the directory protection settings page of cpanel and added the username/password there. So cpanel took care of the server administration. However I have no clue if that still works.

有一个可用的库,你可以用它来创建的.htaccess和htpasswd文件也是如此。我从来没有使用过,所以我不能说,如果它的工作原理:的类:PHP函数类

There is a library available that you can use to create the .htaccess and the .htpasswd files as well. I have never used it so I can not say if it works: Class: PHP Functions Class

我几分记住一些其他图书馆,以及,做只的.htaccess和htpasswd的东西,所以你可能会发现别的东西与互联网搜索。

I sort of remember some other library as well that does only the .htaccess and .htpasswd stuff, so you might find something else with searching the internet.