PHP user authentication and management full source code. -- Beginauth. inc --? Php (as the mainstream development language) idxxxCOM; if (! Isset (php (as the mainstream development language) _ AUTH_USER) Header (WWW-Authenticate: Basicrealmid -- begin auth. inc --
$ Id = "xxxCOM ";
If (! Isset ($ php (as the mainstream development language) _ AUTH_USER )){
Header ("WWW-Authenticate: Basic realm =" $ id "");
Header ("HTTP/1.0 401 Unauthorized ");
Require (error. inc );
Exit;
}
$ Name = $ php (as the mainstream development language) _ AUTH_USER;
$ Pass = $ php (as the mainstream development language) _ AUTH_PW;
Require ("connect. inc ");
$ Query = "select * from auth where username = $ name & realm = $ id ";
$ Result = MySQL (the best combination with PHP) _ db_query ("admin", $ query );
If (MySQL (the best combination with PHP) _ num_rows ($ result) = 0 ){
Header ("WWW-Authenticate: Basic realm =" $ id "");
Header ("HTTP/1.0 401 Unauthorized ");
Require (error. inc );
Exit;
}
$ Active = MySQL (the best combination with PHP) _ result ($ result, 0, "active ");
If ($ active = no ){
?>
404 Not Found
Not Found
The requested URL
Was not found on this server.
Exit;
}
?>
-- End auth. inc --
-- Begin connect. inc --
-- End connect. inc --
-- Begin error. inc --
This file stores error messages and returns!
-- End error. inc --
-- User library structure (self-adjusted )--
Create table auth (
Id smallint (6) DEFAULT 0 not null auto_increment,
Username varchar (16) default not null,
Lastname tinyblob,
Firstname tinyblob,
Password varchar (16 ),
Realm varchar (16 ),
Active char (3 ),
Prima (the most complete virtual host Management System) ry key (id ),
UNIQUE id (id ),
UNIQUE username (username)
);
-- The user library structure ends --
-- Add user example --
Insert into auth (username, lastname, firstname, password, realm, active) values (admin, my, love, password, xxxCOM, yes );
-- End --
-- The user management program starts usermanage. php (as the mainstream development language )--
If ($ php (as the mainstream development language) _ AUTH_USER! = "Admin "){
Header ("WWW-Authenticate: Basic realm =" xxxCOM customer authentication "");
Header ("HTTP/1.0 401 Unauthorized ");
Echo "access (favorite of small websites) Denied! N ";
Exit;
};
If ($ php (as the mainstream development language) _ AUTH_PW! = "Mypassword "){
Header ("WWW-Authenticate: Basic realm =" xxxCOM customer authentication "");
Header ("HTTP/1.0 401 Unauthorized ");
Echo "access (favorite of small websites) Denied! N ";
Exit;
};
If ($ activate ){
Include ("connect. inc ");
$ Query1 = "UPDATE auth SET active = yes where id = $ id ";
$ Result1 = MySQL (the best combination with PHP) _ db_query ("admin", $ query1 );
If ($ result1 ){
Echo "n ";
Echo "$ user activatedn ";
Http://www.bkjia.com/PHPjc/509057.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/509057.htmlTechArticle -- begin auth. inc --? Php (as the mainstream development language) id = "xxxCOM"; if (! Isset (php (as the mainstream development language) _ AUTH_USER) Header ("WWW-Authenticate: Basic realm =" id...