password protect folders script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

password protect folders script

Post by manRay »

How can I dynamically protect a folder, I know the normal way is to use .htpasswrd file in the respective directory, can I create one from a script? Say, when a user registers on my site.
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: password protect folders script

Post by Gargoyle »

not (directly) possible with php.

you can, however, restrict access to a folder to php through a htaccess file and when a user request a file from that folder, you can hand it to him through php, while direct access through the file url won't work.
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: password protect folders script

Post by manRay »

Wouldn't creating a file with name .htpasswd in the directory, than adding the correcting info into the file work? It would theoretically work right?
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: password protect folders script

Post by manRay »

One more thing, is there be a way to check the user password and login name when they try to access a file from a password protected folder in a php script? Instead of having a popup box asking for a name and password?
Post Reply