HTTP Basic Authentication with PHP
Let us see how to use HTTP Basic Authentication with PHP on the Apache web-server.
It relies on the environment variables PHP_AUTH_USER
and
PHP_AUTH_PW
.
highlight_file("../basiclogin.php"); ?>
|
You may test it here.
Notice that,
- it is crucial that the HTML header is in the very beginning of the output file.
In particular, you must not have any text (or blank spaces, or blank lines!) before the first php tag <?
- the browser stores and resends the authentication information until you close all windows, this is quite nice
- the browser determines the layout of the login form and how many retries a user has, this might be nice
- you need to include the authentication code in every script, this is not so good
- the username and password are written in plain text in the script...this is BAD!