I have 2 things to do.
1) I have to figure out how to get it to check the cookie, that will control my login/logout stuff. Since you can't essentially Logout with the HTTP Authentification. The header is supposed to loop back with $auth == 1 , and then it checks the cookie if the time has expired which expires the cookie, if it has then it goes through the system of bringing up the HTTP Auth box.
2) I know how to do this, i just havn't, i need to md5 my mysql password.
All that happens is the part that says im Authenificated when it matches my user/pass with the mysql database. and then it Auto-refreshes and spams the same page over and over again (the header part, if comment that out, it stops) . The header part is supposed to loop back and if $auth == 0 then go through it again, but if you type it in valid and the $auth == 1, then it should go through and check the cookie . Then I know that the person still wants to be logged on and hasnt expired the cookie, since the HTTP AUthentification might be left logged in and isnt very reliable. Is there an easier way to do this with cookies or something, i want to have this page be included
here's the code :
<?php
// Check to see if $PHP_AUTH_USER already contains info
if ($auth == 1){
print "auth = 1" ;
if ($_COOKIE[user] == md5($_SERVER['PHP_AUTH_USER']) && $_COOKIE[pass] == md5($_SERVER['PHP_AUTH_PW'])){
print "cookie checked" ;
}
exit() ;
}
else if ($auth == 0){
if (!isset($_SERVER['PHP_AUTH_USER'])) {
// If empty, send header causing dialog box to appear
$auth = 0;
header('WWW-Authenticate: Basic realm="ADMIN"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
} else if (isset($_SERVER['PHP_AUTH_USER'])) {
mysql_connect ( "localhost", "------", "------" ) ;
mysql_select_db( "users" ) or die (" Unable to Connect to DB") ;
$sql = "SELECT *
FROM users
WHERE username='{$_SERVER['PHP_AUTH_USER']}' and password='{$_SERVER['PHP_AUTH_PW']}'";
$result = mysql_query($sql) ;
$num = mysql_numrows($result);
if ($num != "0") {
$auth = 1;
$time = time() ;
setcookie ("user", md5($_SERVER['PHP_AUTH_USER']), $time+3200);
setcookie ("pass", md5($_SERVER['PHP_AUTH_PW']), $time+3200);
header("Location: index.php"); /* not sure to include this line or not to have it loop back and check the cookie in $auth==1*/
print "you're authorized" ;
} else {
header('WWW-Authenticate: Basic realm="ADMIN"');
header('HTTP/1.0 401 Unauthorized');
echo 'You h0ser ; take off eh!';
exit;
}
}
}
?>