User Authentication and Management (full version) user authentication and management (full version) Author: MAX Source: Ortho network - 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') {
?>
body> html> php exit;}?>
- End auth.inc -
- Begin Connect.inc -
php mysql_connect ("localhost", "user", "");?>
- End connect.inc -
- Begin Error.inc -
This file stores error message 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 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 Manager Start 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"; }
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'"; $ results1 = mysql_db_query ("admin", $ query1);
IF ($ Result1) {echo " n"; echo "$ user activatedn"; echo "
n Return N"; ECHO " font> n"; exit;} else {echo " n"; echo "error: unknown errorn"; echo "
n Return N "; ECHO" font> n "; exit;}
}
IF ($ deActivate) {
Include ("Connect.inc"); $ query2 = "Update auth set active = 'no' where id = '$ ID'"; $ results2 = mysql_db_query ("admin", $ query2);
IF ($ Result2) {Echo " n"; echo "$ user deactivatedn"; echo "
n Return N"; ECHO " font> n"; exit;} else {echo " n"; echo "error: unknown errorn"; echo "
n Return 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 " n"; echo "$ user has been deleted! n"; echo "
n Back n "; ECHO" font> n "; exit;} else {echo" n "; echo" error: unknown errorn "; echo"
n Return N"; ECHO " font> n"; exit;}
}
Echo " n"; echo "
n"; echo "username font > tH> | real name font> th> | activated font> tH> Tr> n ";
Include ("Connect.inc"); $ query = "select * from auth"; $ results = mysql_db_query ("admin", $ query); if ($ results) {while ($ r = mysql_fetch_array ($ result) { $ ID = $ r ["ID"]; $ usrname = $ r ["username"]; $ lastname = $ r ["lastname"]; $ firstname = $ r ["firstname"]; $ activated = $ r [$ actid = $ r [ "Active"]; if ($ activated == "yes") {echo " $ usrname font> td> | $ lastname, $ firstname font> td> | $ activated font> td> | deactivate td> | delete td> < / TR> N ";} elseif ($ activated ==" no ") {echo" | $ usrname font> td> | $ lastname, $ firstname font> td> | $ activated font> td> | Activate td> | delete td> Tr> n ";}}} mysql_free_result ($ result); echo" table> n "; echo" body> n "; ECHO" html> n ";
| ?> - UserManage.php end -
转载请注明原文地址:https://www.9cbs.com/read-1018.html New Post(0)
|
---|