PDA

View Full Version : htaccess/htpasswd login using a php script?


kermit f
03-30-2007, 12:45 PM
Is there anyway to login to a htaccess/htpasswd protected area using a php script? I have a password protected directory but would like to replace the usual popup login window with my own html-based login form

shidan
03-30-2007, 01:45 PM
Yes you can..there are websites who tells u how to do so... Try checking it out

Fabian
03-30-2007, 04:15 PM
By htaccess/htpasswd, I assume you are talking about Basic Authentication protection. With this method the default dialogue box that pops up is unavoidable. The reason for this is that no page can execute as permission is being denied, so this includes any page you have made with your beautiful login form in it.

If you want to display a custom login page then don't protect the directory using Basic Auth, you'll have to use a custom method that is handled by PHP.

This kind of authentication in PHP is usually handled by a database solution. You'll also need to know how to maintain the logged in session across multiple pages, because unlike basic auth the password will not be sent to each page that is requested after initial login.

Here's one example tutorial, there will be thousands more.
http://www.devshed.com/c/a/PHP/Creating-a-Secure-PHP-Login-Script/

If you still want to use your htpasswd file instead of a database, then post the question, "how do I check passwords in a htpasswd file from PHP"... I have no idea, and I wouldn't do it