使用PHP3进行HTTP认证_PHP
只有在PHP以Apache的模块方式运行的时候才可以使用HTTP认证的功能。在Apache的模块PHP脚本中,可以使用Header()函数向客户断浏览器发送一个”Authentication Required”的消息,使浏览器弹出一个用户名/密码(username/password)的输入窗口,当用户输入用户名和密码后,包含PHP脚本的URL将会被再次调用,使用分别代表用户名,密码,和确认方式的$PHP_AUTH_USER, $PHP_AUTH_PW,$PHP_AUTH_TYPE变量。现在只有”BASIC”的确认方式被支持。
在一个页面中强迫用户进行身份认证的代码段的例子如下:
Example 2-1. HTTP 认证举例:
if(!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"My Realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Text to send if user hits Cancel button\n";
exit;
}
else {
echo "Hello $PHP_AUTH_USER.
";
echo "You entered $PHP_AUTH_PW as your password.
";
}
?>
除了简单的输出$PHP_AUTH_USER 和 $PHP_AUTH_PW变量的值以外,你还可以检查用户名和密码的合法性,也许是对数据库进行查询,也许是在dbm文件中搜索用户。
当心臭虫成堆的Internet Explorer浏览器,他对Hearders的顺序非常挑剔.所以采用在送出HTTP/1.0 401 header 请求之前送出WWW-Authenticate header请求是一个很好的解决方法。
为了阻止一些人写一些脚本来显示一个经过传统外部机制验证过的页面的密码,采用如下方式:如果这一页面使用外部验证机制,将不会生成PHP_AUTH变量.这样,$REMOTE_USER变量可以被用来表示已经被外部机制验证的用户.
注意,上面的方法并不能防止某些人在同一台服务器上利用无身份验证的URL偷取有身份鉴别的URL的密码。
无论Netscape还是IE,在接到服务器的401回复之后,都将清空本地浏览器窗口的身份验证缓存。这种做法可以有效的使用户登录退出,从而强迫他们再次输入他们的用户名和密码。一些人使用这个方式来实现“超时”注册,或者提供登录退出的按钮。
这种方法不是标准的HTTP基本身份鉴定所必须的,所以您可能从来都不依靠它。使用Lynx进行的测试并没有弄清楚401服务器回应的身份鉴定,所以如果使用“向前”或“向后”功能将打开源文件(只要信用需求还没有被改变)。
虽然已经指出这种语言不能工作在Microsoft的IIS服务器上,但是PHP语言CGI版本将受到IIS的限制。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

When using Win11 system, sometimes you will encounter a prompt that requires you to enter the administrator username and password. This article will discuss how to deal with this situation. Method 1: 1. Click [Windows Logo], then press [Shift+Restart] to enter safe mode; or enter safe mode this way: click the Start menu and select Settings. Select "Update and Security"; select "Restart Now" in "Recovery"; after restarting and entering the options, select - Troubleshoot - Advanced Options - Startup Settings -&mdash

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

Wireless networks have become an indispensable part of people's lives in today's digital world. Protecting the security of personal wireless networks is particularly important, however. Setting a strong password is key to ensuring that your WiFi network cannot be hacked by others. To ensure your network security, this article will introduce in detail how to use your mobile phone to change the router WiFi password. 1. Open the router management page - Open the router management page in the mobile browser and enter the router's default IP address. 2. Enter the administrator username and password - To gain access, enter the correct administrator username and password in the login page. 3. Navigate to the wireless settings page - find and click to enter the wireless settings page, in the router management page. 4. Find the current Wi

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below
