Introduction: This is a detailed page for PHP user authentication and Management (full version). It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 323747 'rolling = 'no'>
User Authentication and Management (Full Edition)
Author: Max
-- Begin Auth. inc --
<? PHP
$ 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 '){
?>
<HTML>
<Title> 404 Not found </title>
</Head> <body>
<H1> not found
The requested URL
<? Echo $ request_uri;?>
Was not found on this server. <p>
</Body>
<? PHP
Exit;
}
?>
-- End Auth. inc --
-- Begin connect. inc --
<? PHP mysql_connect ("localhost", "user", "");?>
-- 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 --
-- User ManagementProgramStart usermanage. php --
<? PHP Include ("Auth. Inc");?>
<? 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 "<font size =" + 1 "> N ";
Echo "$ user activatedn ";
Echo"
N <a href = "$ php_self"> return </a> N ";
Echo "</font> N ";
Exit;
} Else {
Echo "<font size =" + 1 "> N ";
Echo "error: Unknown errorn ";
Echo"
N <a href = "$ php_self"> return </a> N ";
Echo "</font> 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 "<font size =" + 1 "> N ";
Echo "$ user deactivatedn ";
Echo"
N <a href = "$ php_self"> return </a> N ";
Echo "</font> N ";
Exit;
} Else {
Echo "<font size =" + 1 "> N ";
Echo "error: Unknown errorn ";
Echo"
N <a href = "$ php_self"> return </a> N ";
Echo "</font> N ";
Exit;
}
}
If ($ delete ){
Include ("Connect. Inc ");
$ Query3 = "delete from auth where id = '$ id '";
$ Result3 = mysql_db_query ("admin", $ query3 );
If ($ result3 ){
Echo "<font size =" + 1 "> N ";
Echo "$ user deleted! N ";
Echo"
N <a href = "$ php_self"> return </a> N ";
Echo "</font> N ";
Exit;
} Else {
Echo "<font size =" + 1 "> N ";
Echo "error: Unknown errorn ";
Echo"
N <a href = "$ php_self"> return </a> N ";
Echo "</font> N ";
Exit;
}
}
Echo "<HTML> N ";
Echo "
Echo "<title> User management </title> N ";
Echo "
Echo "<body> N ";
Echo "<form method =" Post "Action =" $ php_self "> N ";
Echo "<Table border =" 1 "> N ";
Echo "<tr> <TH> <font size =" + 1 "> username </font> </Th> <TH> <font size =" + 1 "> real
Name </font>
</Th> <TH> <font size = "+ 1"> activated </font> </Th> </tr> 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 "<tr> <TD> <font size =" + 1 "> $ username </font> </TD> <font size =" + 1 "> $ lastname,
$ Firstname </font>
</TD> <font size = "+ 1"> $ activated </font> </TD> <TD>
<A href = "$ php_self? Deactivate = Yes & id = $ ID & User = $ username "> deactivate </a>
</TD> <a href = "$ php_self? Delete = Yes & id = $ id "> Delete </a> </TD> </tr> N ";
} Elseif ($ activated = "no "){
Echo "<tr> <TD> <font size =" + 1 "> $ username </font> </TD> <font size =" + 1 "> $ lastname,
$ Firstname
</Font> </TD> <font size = "+ 1"> $ activated </font> </TD> <
Href = "$ php_self? Activate = Yes & id = $ id "> activate </a>
</TD> <a href = "$ php_self? Delete = Yes & id = $ id "> Delete </a> </TD> </tr> N ";
}
}
}
Mysql_free_result ($ result );
Echo "</table> N ";
Echo "</body> N ";
Echo "
?>
-- Usermanage. php ended --
More articles on "PHP user authentication and Management (Full Edition)"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/323747.html pageno: 15.