IFeelYourPain
11-04-2009, 05:29 AM
I have a password script that I would like to embed php in. Ex:
<?php
$myusername = "usar";
$mypassword = "passward";
$areaname = "Area";
if ($_SERVER["PHP_AUTH_USER"] == "" || $_SERVER["PHP_AUTH_PW"] == "" || $_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword) {
header("HTTP/1.0 401 Unauthorized");
header("WWW-Authenticate: Basic realm=\"$areaname\"");
echo "<h1>Authorization Required</h1>";
die();
}
?>
I'm wondering two things. First is only if option 2 is not available, which is... If the password is incorrect how can I redirect? I found:
header('Location: http://www.example.com/');
But it's not working.
Option 2. I was hoping to display a custom error in php, but anything after the code above is password protected... So is it possible to get PHP inside there to use it as a custom message or would I have to redirect to a php page for this?
<?php
$myusername = "usar";
$mypassword = "passward";
$areaname = "Area";
if ($_SERVER["PHP_AUTH_USER"] == "" || $_SERVER["PHP_AUTH_PW"] == "" || $_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword) {
header("HTTP/1.0 401 Unauthorized");
header("WWW-Authenticate: Basic realm=\"$areaname\"");
echo "<h1>Authorization Required</h1>";
die();
}
?>
I'm wondering two things. First is only if option 2 is not available, which is... If the password is incorrect how can I redirect? I found:
header('Location: http://www.example.com/');
But it's not working.
Option 2. I was hoping to display a custom error in php, but anything after the code above is password protected... So is it possible to get PHP inside there to use it as a custom message or would I have to redirect to a php page for this?