search
Homephp教程php手册浅谈php用户身份认证(二)

                  浅谈php用户身份认证(二)      
                        爆米花 2001年12月28日 www.westxj.net
(二)基于http的多用户验证  
  上次给大家介绍了基于http的单用户验证,这次利用mysql数据库
储存多用户数据,进行多用户验证。
1、首先建立mysql数据库
mysql>create database user;        //建立数据库user
mysql>use user;                    //打开数据库user
mysql>create table user_data(      //建立数据表user_data
id int(9) not null aoto_increment, //id为自动增加整数字段
username varchar(10) not null,     //用户姓名
password varcher(10) not noll,     //密码
primary key(id);                   //设id为主键
);
2、身份验证程序
$error = "/www/error/error.php";
if ($PHP_AUTH_PW=="")                //如密码为空
{              
Header("WWW-Authenticate: Basic realm=\"用户登陆\"");
Header("HTTP/1.0 401 Unauthorized"); //验证
include($error);                     //定向error,php文件
exit;
}
else
{
mysql_connect("localhost", "root", "1234");     //连接数据库
$result = mysql_db_query("user","select password
from user_data where username='$PHP_AUTH_USER'");
                           //送查询字符串到mysql数据库中
$row = mysql_fetch_array($result); //返回数组资料
$passwd = $row[0];
mysql_close($db_id);               //关闭数据库  
if ($PHP_AUTH_PW!=$passwd)      //密码验证
{
Header("WWW-Authenticate: Basic realm=\"用户登陆\"");
Header("HTTP/1.0 401 Unauthorized");
include($error);
exit;
}
}   




Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.