Hey guys it's me again. Okay so far I've been helped out prety good by this site and it's users. But now I have a more advanced problem dealing with authentication. My problem is that my authentication script doesn't work. Can anyone help me out with it. Thanks
The problem is that I can't get it to authenticate even tho my information entered is correct.
Code:
<?php
require("common.php");
require("globals.php");
function authenticate()
{
header('[URL unfurl="true"]WWW-Authenticate:[/URL] Basic realm="administration"');
header('HTTP/1.0 401 Unauthorized');
printf("<script language\"javascript\" type=\"text/javascript\">alert(\"Please Login\"); </script>");
}
/*if(!$_SESSION['allowed'] == TRUE)
{
header("Location: [URL unfurl="true"]http://".$_SERVER[/URL]['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/login");
} */
if((!isset($_SERVER['PHP_AUTH_USER'])) || ($_POST['login']))
{
authenticate();
}
else
{
$user = $_SERVER['PHP_AUTH_USER'];
$passwd = $_SERVER['PHP_AUTH_PW'];
if($result = execute_query("SELECT uid passwd FROM auth WHERE uname='$user'", 0))
{
$auth_parms = mysql_fetch_object($result[0], 0);
//echo "uname == ".$auth_parms->uname." passwd == ".$auth_parms->passwd;
if($auth_parms->passwd == $passwd)
{
session_start();
$_SESSION['allowed'] = TRUE;
execute_query("INSERT INTO auth SET sessionid='SID' WHERE uid='$auth_parms->uid'";
header("Location: [URL unfurl="true"]http://".$_SERVER[/URL]['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/admin");
}
else
{
printf("<script language=\"javascript\" type=\"text/javascript\">alert(\"Invalid username or password\");</script>");
authenticate();
}
}
}
//echo "uname == ".$auth_parms->uname
echo "user == ".$_SERVER['PHP_AUTH_USER']." passwd == ".$_SERVER['PHP_AUTH_PW'];
printf("<center><div class=\"content\"><table class=\"content\">
<form name=\"login_admin\" method=\"post\" action =\"%s\">
<input type=\"submit\" value=\"login\" name=\"login\">
</form></table></div>", $_SERVER['PHP_SELF']);
printf("<p>login to access administrative portion of website</p>");
generate_adminpage_footer();
?>
The problem is that I can't get it to authenticate even tho my information entered is correct.