tags:

views:

139

answers:

1

I have a php page from where my users log-in to the application. It is working fine. Yesterday, all of a sudden the users were able to login but were forced out and redirected to the login page again.

My database has logged in the user's login timings and this problem was automatically solved after about 2 hours.

Why will like this happen?


In the following code it will check for the session value and if it is not found then redirect to the error page. Yesterday, it was redirecting to error page even if the session value was set.

<?php
if($_SESSION['ucd']<>"" && $_SESSION['sid']<>"" && $_SESSION['sid']<>0)
{
$query="select count(*) from active_sessions where user_cd='".$_SESSION['ucd']."'
and session_no='".$_SESSION['sid']."' and START_TM like DATE_FORMAT(now(),'%Y-%m-%d%')";
//echo $query;
$cnt=$dbop->select($query);
if($cnt[0] == '0')
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
else{
$query = "update active_sessions set LAST_ACTIVITY = NOW() WHERE SESSION_NO = ".$_SESSION['sid'];
mysql_query($query);
?>

<?php
}
}
else
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
?>
+1  A: 

I don't see session_start() anywhere in your code.

p.s. nice acceptance rate.

Mike B