search
Homephp教程php手册php创建基本身份认证站点的方法详解

本篇文章是对php创建基本身份认证站点进行了详细的分析介绍,需要的朋友参考下

默认情况下,大多数web服务器一般被配置为匿名访问,也即为,美国空间,用户在访问服务器上的信息时一般不会被要求提示标识信息。匿名访问意味着用户不使用用户名和密码登陆就可以访问网站。这也是绝大多数公共网站所使用的配置。
在Apache的配置文件“httpd.conf”中,默认被配置为匿名访问(如下):

复制代码 代码如下:



Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow,deny
Allow from all


--------------------------------------------------------------------------------
要强制浏览器使用基本身份认证,必须传递一个WWW-Authenticate字段,例如下边的代码使用header()函数来要求客户端使用BASIC验证,美国空间,它在HTTP消息报头中增加一个WWW-Authenticate字段:
header("WWW-Authenticate:BASIC Realm=My Realm");
--------------------------------------------------------------------------------
下边写一个使用

复制代码 代码如下:


if(!isset($_SERVER['PHP_AUTH_USER'])){
header("WWW-Authenticate:BASIC Realm=My Realm");
header("HTTP/1.0 401 Unauthorized");
echo("账号/密码错误!");
exit;
}else{
/*获取用户名,密码进行验证*/
$user=$_SERVER['PHP_AUTH_USER'];
$pwd=$_SERVER['PHP_AUTH_PW'];
if($user=="admin"&&$pwd="password"){
echo "通过验证";
}else{
header("HTTP/1.0 401 Unauthorized");
echo "账号/密码错误!";
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools