Discussion on user authentication of PHP (II.)

Source: Internet
Author: User
Discussion on user authentication of PHP (II.)
Popcorn December 28, 2001 Www.westxj.net
(ii) Multi-user authentication based on HTTP
The last time we introduced a single user authentication based on HTTP, this time using MySQL database
Multi-user data is stored for multi-user authentication.
1, first set up MySQL database
Mysql>create database user; Build database User
Mysql>use user; Open Database User
Mysql>create table User_data (//Set up datasheet user_data
ID Int (9) NOT null aoto_increment,//id to automatically increment integer digit segment
Username varchar (%) not NULL,//user name
Password Varcher (ten) not Noll,//password
Primary key (ID); Set ID as primary key
);
2. Authentication Program
<?php
$error = "/www/error/error.php";
if ($PHP _auth_pw== "")//If the password is empty
{
Header ("www-authenticate:basic realm=\" user login \ "");
Header ("http/1.0 401 Unauthorized"); Verify
Include ($error); Directed error,php files
Exit
}
Else
{
mysql_connect ("localhost", "root", "1234"); Connecting to a database
$result = Mysql_db_query ("User", "Select password
From User_data where username= ' $PHP _auth_user ');
Send query string to MySQL database
$row = Mysql_fetch_array ($result); Return array Data
$passwd = $row [0];
Mysql_close ($db _id); Close Database
if ($PHP _auth_pw!= $passwd)//password verification
{
Header ("www-authenticate:basic realm=\" user login \ "");
Header ("http/1.0 401 Unauthorized");
Include ($error);
Exit
}
}




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.