avsc
asked on
How can I restrict access to a .php page?
I have PHP5 running on Windows 2003/IIS6. I need to restrict access to a certain .php page to a single user. How can I best accomplish this task?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
AFAIK $_SERVER["PHP_AUTH_PW"] is not guarateed to be set by the server, depends on the web server
include this php code at the beginning of your php file. Just change the the password to whatever you want!!
//========================
// Authenticate //
//========================
$PHP_AUTH_USER=$_SERVER["P
$PHP_AUTH_PW=$_SERVER["PHP
if (!isset($PHP_AUTH_USER) && !isset($PHP_AUTH_PW)) {
Header("WWW-Authenticate: Basic realm=Authenticate");
echo "Authentication required!";
exit;
}
if ($PHP_AUTH_USER == '') {
Header("WWW-Authenticate: Basic realm=Authenticate");
echo "Authentication required!";
exit;
}
if ($PHP_AUTH_USER != 'yourUserid' || $PHP_AUTH_PW != 'yourPassword') {
Header("WWW-Authenticate: Basic realm=Authenticate");
echo "Authentication required!";
exit;
}