Basic authentication in PHP PEAR

xiaoxiao2021-03-06  37

Basic authentication in PHP PEAR

The required documents: Pear DB, Auth Table Structure Create Table Auth (Username Varchar (50) Default '' NOT NULL, Password Varchar (32) Default '' NOT NULL, Primary Key (UserName), Key (Password);

Code: ; echo" "; echo" "; echo" "; echo" ";} // Control whether the login dialog should IF ( ISSET ($ _ get ['login']) && $ _GET ['login'] == 1) {$ Optional = true;} else {$ Optional = false;} $ dsn = "mysql: // user: pass @ localhost / AUTHDB "; $ a = new author (" db ", $ dsn," loginfunction ", $ optional); $ a-> start (); if (! isset ($ _ get ['login'))) {echo" Click Here to log in / n";} if ($ A-> GetAuth) )) {// add some code here echo " Logout
getAuth ()) {$ A-> logout (); $ a-> start ();}?>

Such a simple verification program is fine, you can expand its user interface yourself. Note: The default password plus password is md5, ie IF (MD5 ($ _ post ['password') === password), the table name and field name cannot change, the password of Password is 32, which is 32, is introduced by the form. The form of form is verified, and the following is to authenticate by sending Headers information to the client. Auth_http

"mysql: // user: pass @ localhost / authdb", "Table" => "Auth" , "UserNamecol" => "username", // username field "passwordcol" => "password", // password field "crypttype" => "md5", // password encryption method, plaintext verification 'None' ' DBFIELDS '=> "*", // With other fields in the table, all *); $ au = new auth_http ("db", $ options); $ au-> setExpire (5); $ au-> SetRealm ("Please enter the authentication information:"); $ au-> setcanceltext ("


New Post(0)