PHP user authentication and management full source code & lt ;? Php <br/> $ id = & quot; xxxCOM & quot; <br/> <br/
$ Id = "xxxCOM ";
If (! Isset ($ PHP_AUTH_USER )){
Header ("WWW-Authenticate: Basic realm =" $ id "");
Header ("HTTP/1.0 401 Unauthorized ");
Require ('error. Inc ');
Exit;
}
$ Name = $ PHP_AUTH_USER;
$ Pass = $ PHP_AUTH_PW;
Require ("connect. inc ");
$ Query = "select * from auth where username = '$ name' & realm =' $ ID '";
$ Result = mysql_db_query ("admin", $ query );
If (mysql_num_rows ($ result) = 0 ){
Header ("WWW-Authenticate: Basic realm =" $ id "");
Header ("HTTP/1.0 401 Unauthorized ");
Require ('error. Inc ');
Exit;
}
$ Active = mysql_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 ),
Primary 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 --
If ($ PHP_AUTH_USER! = "Admin "){
Header ("WWW-Authenticate: Basic realm =" xxxCOM customer authentication "");
Header ("HTTP/1.0 401 Unauthorized ");
Echo "Access Denied! N ";
Exit;
};
If ($ PHP_AUTH_PW! = "Mypassword "){
Header ("WWW-Authenticate: Basic realm =" xxxCOM customer authentication "");
Header ("HTTP/1.0 401 Unauthorized ");
Echo "Access Denied! N ";
Exit;
};
If ($ activate ){
Include ("connect. inc ");
$ Query1 = "UPDATE auth SET active = 'yes' where id = '$ ID '";
$ Result1 = mysql_db_query ("admin", $ query1 );
If ($ result1 ){
Echo "n ";
Echo "$ user activatedn ";
Echo"
N returns n ";
Echo "n ";
Exit;
} Else {
Echo "n ";
Echo "Error: Unknown Errorn ";
Echo"
N returns n ";
Echo "n ";
Exit;
}
}
If ($ deactivate ){
Include ("connect. inc ");
$ Query2 = "UPDATE auth SET active = 'no' where id = '$ ID '";
$ Result2 = mysql_db_query ("admin", $ query2 );
If ($ result2 ){
Echo "n ";
Echo "$ user deactivatedn ";
Echo"
N returns n ";
Echo "n ";
Exit;
} Else {
Echo "n ";
Echo "Error: Unknown Errorn ";
Echo"
N returns n ";
Echo "n ";
Exit;
}
}
If ($ delete ){
Include ("connect. inc ");
$ Query3 = "delete from auth where id = '$ ID '";
$ Result3 = mysql_db_query ("admin", $ query3 );
If ($ result3 ){
Echo "n ";
Echo "$ user deleted! N ";
Echo"
N returns n ";
Echo "n ";
Exit;
} Else {
Echo "n ";
Echo "Error: Unknown Errorn ";
Echo"
N returns n ";
Echo "n ";
Exit;
}
}
Echo"N ";
Echo"N ";
Echo"User ManagementN ";
Echo"N ";
Echo"N ";
Echo"
N ";
Echo"
N ";Echo"
Username |
Real Name |
Activated |
N ";Include ("connect. inc ");$ Query = "SELECT * FROM auth ";$ Result = mysql_db_query ("admin", $ query );If ($ result ){While ($ r = mysql_fetch_array ($ result )){$ Id = $ r ["id"];$ Username = $ r ["username"];$ Lastname = $ r ["lastname"];$ Firstname = $ r ["firstname"];$ Activated = $ r ["active"];If ($ activated = "yes "){Echo"
$ Username |
$ Lastname, $ firstname |
$ Activated |
Deactivate |
Delete |
N ";} Elseif ($ activated = "no "){Echo"
$ Username |
$ Lastname, $ firstname |
$ Activated |
Activate |
Delete |
N ";}}}Mysql_free_result ($ result );Echo"
N ";
Echo"N ";
Echo"N ";
?>
-- Usermanage. php ended --