IMHO, the whole point of using HTTP authentication is being able to delegate authentication tasks:
- The web server takes care of denying unauthorized access to protected resources
- The browser takes care of asking for username and password when required
So you have a working system with minimum effort.
Now, if you use an HTML form to ask for credentials, the server will know who you are but the browser won't: it'll ask for credentials as soon as it finds the WWW-Authenticate
response header and the 401
status code. For this to work, the browser has to send an Authorization
request header on every HTTP request; however, your form cannot instruct the browser to send the appropriate HTTP header.
Of course, you can write your own server-side authentication code in PHP, configure the server to parse static files through it and omit 401
and WWW-Authenticate
as soon as you get valid credentials (which then need to be stored somewhere else, e.g., a PHP session). But then you've lost all the advantages of HTTP authentication: at this point, a custom login handler with PHP sessions will be a much easier solution.
To sum up:
- If you need simplicity, forget about HTML forms
- If you need HTML forms, write your own code