Sessions in php logs me out immediately

89 Views Asked by At

I'm new to php and stuck with old code written for php4. Everything seems to be working fine, I even got a quick fix for register_globals here. The thing is, I get logged out immediately after clicking any link so I suspect this time it is a session issue. Please check this for me:

<?
foreach (array_merge($_GET, $_POST) as $key => $val) {
  global $$key;
  $$key = addslashes($val);
}
@session_start(); 
include("../dbinfo.php");
$expireTime = 60;
@session_set_cookie_params($expireTime);

if(isset($bye)) {
    $_SESSION['session_unregister']= 'login';
    $_SESSION['session_unregister']= 'password';
    $_SESSION['time']= time();
    include("logout.php"); 
    exit;
        } 
if(!isset($login)) { 
    include("loginform.php");
exit; }

$_SESSION['login']= 'login';
$_SESSION['password']= 'password';
mysql_connect($DBhost, $DBuser, $DBpass) or DIE("Unable to connect to database");
@mysql_select_db($DBName) or die("Unable to select database");

$myquery="select loginname,password from $table where loginname='$login' and   password='$password'";
$result = mysql_query($myquery);
$num_result = mysql_num_rows($result);

if(!$num_result) { 
    $_SESSION['session_unregister']= 'login';
    $_SESSION['session_unregister']= 'password';
    ?>
        <html>
            <head>
            <title> Access Denied </title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body bgcolor="#CCCCCC">
<h1> Access Denied </h1>
            <p>Your user ID or password is incorrect, or you are not a
        registered user on this site. To try logging in again, click
            <a href="<?=$PHP_SELF?>">here</a>.</p>
            </body>
        </html>

<? exit;
}
?>  

<

0

There are 0 best solutions below