PHP Implements user authentication and manages full source code _ php instances

Source: Internet
Author: User
PHP full source code for user authentication and Management -- 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 "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" 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"
Username Real Name Activated
$ Username $ Lastname, $ firstname $ Activated Deactivate Delete
$ Username $ Lastname, $ firstname $ Activated Activate 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.