Php user authentication and Management (full edition)

Source: Internet
Author: User
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" 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" N ";} Elseif ($ activated = "no "){Echo" N ";}}}Mysql_free_result ($ result );Echo"
+ 1 "> Username + 1 "> Real

Name

+ 1 "> Activated
+ 1 "> $ username + 1 "> $ lastname,

$ Firstname

+ 1 "> $ activated

$ PHP_SELF? Deactivate = yes & id = $ id & user = $ username "> Deactivate

$ PHP_SELF? Delete = yes & id = $ id "> Delete
+ 1 "> $ username + 1 "> $ lastname,

$ Firstname

+ 1 "> $ activated
Href = "$ PHP_SELF? Activate = yes & id = $ id "> Activate

$ PHP_SELF? Delete = yes & id = $ id "> Delete
N ";

Echo"N ";

Echo"N ";



?>



-- Usermanage. php ended --

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.