The premise is to install the auth class library and the auth_http class library
The code is as follows:
Require_once ("Auth/HTTP. php ");
// Set database connection options
$ Auth_options = array (
'Dsn '=> "mysql: // root: 1981427 @ localhost/test", // database connection string
'Table' => "tablename1", // table name
'Usernamecol' => "username", // column used to store the user name
'Passwordcol' => "password", // column used to store passwords
'Crypttype' => "none", // password encryption method
);
// Create an Auth_HTTP object, specifying that the database is used as the information source
$ Auth = new Auth_HTTP ("DB", $ auth_options );
// Description on the setting dialog box
$ Auth-> setRealm ('login ');
// Error message when identity verification fails or the user cancels
$ Auth-> setCancelText ('authentication failed! ');
// Start user identity verification
$ Auth-> start ();
// If the identity verification is successful, the information is displayed.
If ($ auth-> getAuth ())
{
Echo "authentication successful, welcome". $ auth-> username;
};
?>