Hey guys I am having a problem with new code that I think should work. I poseted a thread a few days ago stating that I couldn't get some stuff to work but I figured it out. Now I have the code "working" but I still have a problem. When I use firefox and everything validates I get a redirecton limit error. When I use IE I get an error page saying that the page can't load.
here's the code that is placed at the top of every admin script
validate.php
and here's the login that checks user information and validates it then sets the session variables and info
here's the code that is placed at the top of every admin script
validate.php
Code:
<?php
if(($_SESSION['allowed'] != 1) || ($_SESSION['user_ip'] != $_SERVER['REMOTE_ADDR']) || (session_id() != $_SESSION['session_id']))
{
header("Location: [URL unfurl="true"]http://".$_SERVER[/URL]['SERVER_ADDR']
.dirname($_SERVER['PHP_SELF'])
."/login");
}
?>
and here's the login that checks user information and validates it then sets the session variables and info
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');
}
if(!isset($_SERVER['PHP_AUTH_USER']))
{
authenticate();
}
else
{
$user = $_SERVER['PHP_AUTH_USER'];
//$passwd = $_SERVER['PHP_AUTH_PW'];
$result = execute_query("SELECT uid, passwd, uname FROM auth WHERE uname='$user' ", 0);
if($result[0])
{
$auth_parms = mysql_fetch_object($result[0]);
//echo "uname == ".$auth_parms->uname." passwd == ".$auth_parms->passwd;
if($_SERVER['PHP_AUTH_PW'] == $auth_parms->passwd || $_SERVER['PHP_AUTH_USER'] == $auth_parms->uname)
{
$sess_name = session_name($auth_parms->uname.$auth_parms->uid); //
session_start();
$sess_id = session_id();
$_SESSION['allowed'] = 1;
$ip_addr = $_SERVER['REMOTE_ADDR'];
$uid = $auth_parms->uid;
//$cookie_parms = array("session_id", "session_name", "user_ip");
$cookie = array($sess_id, $sess_name, $ip_addr);
$_SESSION['session_name'] = $sess_name;
$_SESSION['session_id'] = $sess_id;
$_SESSION['user_ip'] = $ip_addr;
$_SESSION['uid'] = $uid;
execute_query("UPDATE auth SET sessionid='$sess_id', ip='$ip_addr', cookie='$cookie[0].$cookie[0].$cookie[2].$cookie[3]' WHERE uid='$uid' ", 0);
//printf("<center><a href=\"[URL unfurl="true"]http://%s/admin/\"><input[/URL] type=\"button\" value=\"continue\"></a>", $_SERVER['HTTP_HOST']);
header("Location: [URL unfurl="true"]http://".$_SERVER[/URL]['SERVER_ADDR'].dirname($_SERVER['PHP_SELF'])."/admin");
}
else
{
authenticate();
}
}
}
echo("session_id ==".$_SESSION['session_id']);
echo("session_name ==".$_SESSION['session_name']);
echo("allowed ==".$_SESSION['allowed']);
echo("user_ip ==".$_SESSION['user_ip']);
echo("uid ==".$_SESSION['uid']);
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();
?>