PHP password protect – is a script which you need to protect some page generated with PHP. Password protection for a single page. Visitors are required to enter a password and username to view the page content.
Just include this function into your code, and call it at the top of your page with valid USERNAME and PASSWORD.
Source code for webtoolkit.protect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/**
*
* PHP password protect
* http://www.webtoolkit.info/
*
**/
function passwordProtect($username, $password){
if (
(
!isset($_SERVER['PHP_AUTH_USER']) ||
(
isset($_SERVER['PHP_AUTH_USER']) &&
$_SERVER['PHP_AUTH_USER'] != $username
)
) &&
(
!isset($_SERVER['PHP_AUTH_PW']) ||
(
isset($_SERVER['PHP_AUTH_PW']) &&
$_SERVER['PHP_AUTH_PW'] != $password
)
)
)
{
header('WWW-Authenticate: Basic realm="Login"');
header('HTTP/1.0 401 Unauthorized');
echo 'Please login to continue.';
exit;
}
}
|