PHP user authentication and management full source _php

Source: Internet
Author: User
Keywords Full source management authentication user Echo
--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 ') {


?>



<title>404 Not Found</title>



Not Found



The requested URL



Was wasn't found on the this server.






Exit

}

?>


--End Auth.inc--


--Begin Connect.inc--





--End Connect.inc--


--Begin Error.inc--


This file holds the error message and returns!


--End Error.inc--


--User library structure (self-tuning)--


CREATE TABLE Auth (

ID smallint (6) DEFAULT ' 0 ' not NULL auto_increment,

Username varchar (+) 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)

);


--end of user library structure--


--Add User example--


Insert into auth (username, lastname, firstname, password, realms, Active) values (' admin ', ' my ', ' love ', ' Password ', ' Xxxcom ', ' yes ');


--End--


--User Management program started 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");

$query 1 = "UPDATE auth SET active= ' yes ' where id= ' $id '";

$result 1 = mysql_db_query ("admin", $query 1);


if ($result 1) {

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");

$query 2 = "UPDATE auth SET active= ' no ' where id= ' $id '";

$result 2 = mysql_db_query ("admin", $query 2);


if ($result 2) {

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");

$query 3 = "Delete from auth where id= ' $id '";

$result 3 = mysql_db_query ("admin", $query 3);


if ($result 3) {

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 "<title>User Management</title>n ";

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 ["Lastn Ame "]; $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 End--
  • Related Article

    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.