This is my code...
<?php
//File Name : HTTP_Auth_2.php
ob_start();
session_start();
require "connect.php";
if(!isset($_SERVER['PHP_AUTH_USER']))
{
auth();
echo '<h1>Hacking Attemped</h1>';
exit();
}
else
{
$username = addslashes(strip_tags($_SERVER['PHP_AUTH_USER']));
$pass = addslashes(strip_tags($_SERVER['PHP_AUTH_PW']));
$result = mysql_query("select * from user where name='$username' and pass='$pass'") or die(mysql_error());
$data = mysql_fetch_array($result);
if(($data[pass] == $pass) && ($data[name] == $username))
{
session_register("username");
session_register("pass");
$_SESSION['username'] = $username;
$_SESSION['pass'] = $pass;
header("Location:home.php");
exit();
}
else
{
auth();
echo "Enter a valid username and password !!";
}
}
function auth()
{
header('WWW-Authenticate: Basic realm="Restricted Area"');
header('HTTP/1.0 401 Unauthorized');
}
ob_end_flush();
?>
<?php
//File Name : logout.php
ob_start();
session_start();
unset($_SESSION['username']);
unset($_SESSION['pass']);
session_destroy();
header("Location:HTTP_Auth_2.php");
ob_end_flush();
?>
Problem :
- Planning Algorithm : HTTP_Auth_2.php (redirect) -> home.php -> logout.php (redirect) -> HTTP_Auth_2.php
- Implementation Algorithm : HTTP_Auth_2.php -> home.php ->logout.php
on implementation, after i press link to logout.php, my browser doesn't want go to page HTTP_Auth_2.php.
It stop in page logout.php !! Why ??? And if i use a new tab but in the same window in Firefox, and then i access page HTTP_Auth_2.php, my browser directly go to the page home.php and bypass page HTTP_Auth_2.php !!
But, when i close that browser and start a new window, i go to page HTTP_Auth_2.php, it show me HTTP Auth...
I think the problem in session...
Pliz correct me...
Thanx for the answer and the respon...
best regards...
joe
