Password protect an entire directory with PHP authentication
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 开发者_StackOverflow中文版but I can't seem to find out how to use PHP and MySQL along with that.
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
- http://www.widexl.com/tutorials/htaccess.html#auth_mysql
- http://www.diegonet.com/support/mod_auth_mysql.shtml
- http://modauthmysql.sourceforge.net/CONFIGURE
A very basic example to do it without .htaccess and mod_auth_mysql
can be found at
- http://www.weberdev.com/get_example-82.html
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.
精彩评论