views:

176

answers:

1

I want to password protect an entire directory and authenticate users though a MySQL database using PHP. I know you can password protect directories using .htaccess but I can't seem to find out how to use PHP and MySQL along with that.

+2  A: 

When using Basic or Digest authentication to protect a folder, you are usually authenticating against a file on the server. That's probably why you didn't find any tutorials on using this with MySQL. You would have to use mod_auth_mysql to make this work from an .htaccess file.

See

A very basic example to do it without .htaccess and mod_auth_mysql can be found at

It should be noted that the script is not properly sanitizing the user input and it is also not using any encryption for the password. It's not a good script, but it has everything to get you into the right direction.

Also see the PHP manuals chapter on HTTP authentication with PHP.

Gordon