User authentication and Management (full edition) Author: MAX user authentication and Management (full edition)
Author: MAX
-- Begin auth. inc --
$ 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 "+ 1"> n ";
Echo "$ user activatedn ";
Echo"
N $ PHP_SELF "> Return n ";
Echo "n ";
Exit;
} Else {
Echo "+ 1"> n ";
Echo "Error: Unknown Errorn ";
Echo"
N $ PHP_SELF "> Return 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 "+ 1"> n ";
Echo "$ user deactivatedn ";
Echo"
N $ PHP_SELF "> Return n ";
Echo "n ";
Exit;
} Else {
Echo "+ 1"> n ";
Echo "Error: Unknown Errorn ";
Echo"
N $ PHP_SELF "> Return 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 "+ 1"> n ";
Echo "$ user deleted! N ";
Echo"
N $ PHP_SELF "> Return n ";
Echo "n ";
Exit;
} Else {
Echo "+ 1"> n ";
Echo "Error: Unknown Errorn ";
Echo"
N $ PHP_SELF "> Return n ";
Echo "n ";
Exit;
}
}
Echo"N ";
Echo"N ";
Echo"User ManagementN ";
Echo"N ";
Echo"N ";
Echo"
N ";
Echo"
N ";Echo"
+ 1 "> Username |
+ 1 "> Real
Name
|
+ 1 "> 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"
+ 1 "> $ username |
+ 1 "> $ lastname,
$ Firstname
|
+ 1 "> $ activated |
$ PHP_SELF? Deactivate = yes & id = $ id & user = $ username "> Deactivate
|
$ PHP_SELF? Delete = yes & id = $ id "> Delete |
N ";} Elseif ($ activated = "no "){Echo"
+ 1 "> $ username |
+ 1 "> $ lastname,
$ Firstname
|
+ 1 "> $ activated |
Href = "$ PHP_SELF? Activate = yes & id = $ id "> Activate
|
$ PHP_SELF? Delete = yes & id = $ id "> Delete |
N ";}}}Mysql_free_result ($ result );Echo"
N ";
Echo"N ";
Echo"N ";
?>
-- Usermanage. php ended --