We help IT Professionals succeed at work.

PHP basic authentication set up

portal123 asked
Hello, I would like to set up PHP and Apache configuration for PHP basic authentication. What do I need to configure it? Version php 4.4.7, Apache 1.3.37, MySQL 4.0.27-standard.

Best Regards, portal123
Watch Question

some nice step by step how to is here, it explains every little thing all the way


Thank, dr_dedo. but I prefer to use $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] without session

and generate query from a mysql table that contains user id and password. comparing $_POST variables with user id and password at the query.  I made the following code and it works well at a previous server, but I've changed a new server and it does not work on it.

So, I guess probably some setting problems on Apache and PHP.

Do I need to set anything on PHP and Apache when I use $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] on them ??
The method given in the article pointed out by dr. dedo exemplifies the process of implementing the authentication process as part of the application itself via html forms.

On the other hand, if you are using the PHP module (not CGI), you may implement HTTP-protocol authentication. The difference is that the browser will pop-up an username/password window and the script will be able to handle the authentication itself. A complete example of this may be found in:

Finally, authentication may be handled entirely by the web server (Apache). The documentation about how to do this is here:
Notice that when authentication is handle this way, you may use one of several apache modules to handle the username/password database, such as mod_auth_db for using a database.

One more note: It is recommended to use digest authentication (as opposed to basic authentication) because in this mode the password does not traverse the network.


I made a simple mistake on $_SERVER['PHP_AUTH_PW']. I wrote not $_SERVER['PHP_AUTH_PW'] but $_SERVER['PHP_AUTH_PWD'] .

Anyway, thanks both guys....
for($i=1; $i<=100; $i++){
echo "THANKS";
echo "<BR />";
Best Regards, portal123

Explore More ContentExplore courses, solutions, and other research materials related to this topic.