PHP user authentication and management full source code _ PHP Tutorial

Source: Internet
Author: User
PHP user authentication and management full source code. -- Beginauth. inc --? Php (as the mainstream development language) idxxxCOM; if (! Isset (php (as the mainstream development language) _ AUTH_USER) Header (WWW-Authenticate: Basicrealmid -- begin auth. inc --




$ 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 ){


?>



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 ),

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





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

Echo "$ user activatedn ";

Http://www.bkjia.com/PHPjc/509057.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/509057.htmlTechArticle -- 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...

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.