Specifications

5. After following the other steps in Appendix A, you will need to create a database and
table in MySQL to contain authentication information. This does not need to be a sepa-
rate database or table; you can use an existing table such as the auth database from the
example earlier in this chapter.
6. Add a line to your httpd.conf file to give mod_auth_mysql the parameters it needs to
connect to MySQL. The directive will look like
Auth_MySQL_Info hostname user password
Did It Work?
The easiest way to check whether your compilation worked is to see whether Apache will start.
To start Apache, type
/usr/local/apache/bin/apachectl startssl
If it starts with the Auth_MySQL_Info directive in the httpd.conf file, mod_auth_mysql was
successfully added.
Using mod_auth_mysql
After you have successfully installed the module, using it is no harder than using mod_auth.
Listing 14.9 shows a sample .htaccess file that will authenticate users with encrypted pass-
words stored in the database created earlier in this chapter.
LISTING 14.9 .htaccessThis .htaccess File Authenticates Users Against a MySQL
Database
ErrorDocument 401 /chapter14/rejection.html
AuthName “Realm Name”
AuthType Basic
Auth_MySQL_DB auth
Auth_MySQL_Encryption_Types MySQL
Auth_MySQL_Password_Table auth
Auth_MySQL_Username_Field name
Auth_MySQL_Password_Field pass
require valid-user
You can see that much of Listing 14.9 is the same as Listing 14.7. We are still specifying
an error document to display in the case of error 401 (when authentication fails). We again
Implementing Authentication with PHP and MySQL
C
HAPTER 14
14
IMPLEMENTING
AUTHENTICATION
323
18 7842 CH14 3/6/01 3:35 PM Page 323