PHP user authentication and Management full source code

Source: Internet
Author: User

-- Begin auth. inc --


<? Php (as the mainstream development language)


$ Id = "xxxCOM ";


If (! Isset ($ php (as the mainstream development language) _ AUTH_USER )){

Header ("WWW-Authenticate: Basic realm =" $ id "");

Header ("HTTP/1.0 401 Unauthorized ");

Require (error. inc );

Exit;

}


$ Name = $ php (as the mainstream development language) _ AUTH_USER;

$ Pass = $ php (as the mainstream development language) _ AUTH_PW;

Require ("connect. inc ");

$ Query = "select * from auth where username = $ name & realm = $ id ";

$ Result = MySQL (the best combination with PHP) _ db_query ("admin", $ query );

If (MySQL (the best combination with PHP) _ num_rows ($ result) = 0 ){


Header ("WWW-Authenticate: Basic realm =" $ id "");

Header ("HTTP/1.0 401 Unauthorized ");

Require (error. inc );

Exit;

}


$ Active = MySQL (the best combination with PHP) _ result ($ result, 0, "active ");

If ($ active = no ){


?>

<HTML> <HEAD>

<TITLE> 404 Not Found </TITLE>

</HEAD> <BODY>

<H1> Not Found </H1>

The requested URL

<? Echo $ REQUEST_URI;?>

Was not found on this server. <P>

</BODY> </HTML>

<? Php (as the mainstream development language)

Exit;

}

?>


-- End auth. inc --


-- Begin connect. inc --


<? Php (as the mainstream development language) MySQL (the best combination with PHP) _ 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 ),

Prima (the most complete virtual host Management System) ry 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 (as the mainstream development language )--

<? Php (as the mainstream development language) include ("auth. inc");?>

<? Php (as the mainstream development language)


If ($ php (as the mainstream development language) _ AUTH_USER! = "Admin "){

Header ("WWW-Authenticate: Basic realm =" xxxCOM customer authentication "");

Header ("HTTP/1.0 401 Unauthorized ");

Echo "access (favorite of small websites) Denied! N ";

Exit;

};


If ($ php (as the mainstream development language) _ AUTH_PW! = "Mypassword "){

Header ("WWW-Authenticate: Basic realm =" xxxCOM customer authentication "");

Header ("HTTP/1.0 401 Unauthorized ");

Echo "access (favorite of small websites) Denied! N ";

Exit;

};


If ($ activate ){


Include ("connect. inc ");

$ Query1 = "UPDATE auth SET active = yes where id = $ id ";

$ Result1 = MySQL (the best combination with PHP) _ db_query ("admin", $ query1 );


If ($ result1 ){

Echo "<font size =" + 1 "> n ";

Echo "$ user activatedn ";

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.