HTTP Authentication
New to PHP 4 is the ability to do HTTP authentication, although it is available only when running PHP as a module with Apache. HTTP authentication is a way to protect a file or directory by requiring users to enter a username and password in a pop-up window to gain access (Figure 8.1).
Figure 8.1. An HTTP authentication prompt.
An authentication prompt is created using the line
header ('WWW-Authenticate: Basic realm="Some Caption"');
The realm attribute can be changed to give the box whatever description you want (for example, My Web Site in Figure 8.1).
Normally you would follow up this line with
header ('HTTP/1.0 401 ...
Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.