Web Hosting Talk







View Full Version : Password protecting a folder?


ilyash
09-22-2005, 06:02 PM
How would I password protect a folder without using htaccess?

I am making a site, and the hoster does not support htaccess.

Thanks for your help.

Burhan
09-22-2005, 06:21 PM
A few ways to approach this problem. The easiest being -- put the actual contents of the file outside the web root, then have a script serve any requests to files in that directory (and have this script do the authentication).

I once had to do something similar -- but in my case the files were all .html files, so this solution worked. What I did was to add a .htaccess file that force-typed all .html files to .php -- then I added a auto_prepend_file that checked for a session cookie. If the cookie was available, the user was allowed to browse the directory -- if it wasn't there, then they were redirected to a login page. It worked brilliantly, but I'm not sure if this is a viable option for you.

Hope this helps :)

Googled
09-23-2005, 04:29 PM
Hi,

Originally posted by ilyash
I am making a site, and the hoster does not support htaccess.

don't want to be rude but I think he can't use your solution as he ain't allowed to use .htaccess files.



There's many solution to this problem :

- Changing host to someplace allowing .HTACCESS (who doesn't support that !? :))

- Using a script already made (http://www.phpmydirectory.com)

- Doing it yourself, with pretty basic PHP knowledge, you may achieve a basic protection using only a text file with user/pass and adding a small piece of PHP code at the beginning of each of your page <? // if user/pass is not in file then die() .. ?>


*hope that helps*

G