IMHO, the whole point of using HTTP authentication is to delegate authentication tasks:
- The web server will take care of refusing unauthorized access to protected resources.
- The browser will take care of the need to request a username and password
So, you have a working system with minimal effort.
Now, if you use the HTML form to request credentials, the server will know who you are, but the browser will not: it will request credentials as soon as it finds a WWW-Authenticate response header and 401 status code. To do this, the browser must send an Authorization request header for each HTTP request; however, your form cannot tell 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 it using static files, and omit 401 and WWW-Authenticate as soon as you get valid credentials (which should then be stored somewhere else location, for example, a PHP session). But then you lost all the benefits of HTTP authentication: for now, a custom login handler with PHP sessions will be much simpler.
Summarizing:
- If you need simplicity, forget HTML forms
- If you need HTML forms, write your own code.
source share