Reputation: 1
Assume two users (A and B) are logged in a PHP application.
While both the session going on A session variable are shown to B and vice versa while accessing the same page in the application.
If A refreshes the page his original session values are shown again.
How to avoid this problem ? Please help me.
login page:
session_start();
error_reporting(0); ob_start();
if( (isset($_POST['submit'])) && ($_POST['submit'] == 'login') ) {
$username=addslashes(trim($_POST['stud_id']));
$password=addslashes(trim($_POST['password']));
}
$mysqli->set_charset('utf8'); $query=sprintf("select * from registation_fst where Application_id='%s'",$username);
$result = $mysqli->query($query) or die($mysqli->error);
$rowcount = mysqli_num_rows($result);
if($rowcount > 0)
{
$row = mysqli_fetch_array($result);
$adm_pass= addslashes($row['Password']);
$adm_user= addslashes($row['Application_id']);
if(($username == $adm_user) && ($password == $adm_pass) )
{
$_SESSION['username']=$row['Application_id'];
//$_SESSION['password']=$row['Password'];
$_SESSION['mob'] = $row['Mobile_No'];
$_SESSION['dob'] = $row['DOB'];
$_SESSION['aadhar_no'] = $row['Adhar_no'];
$_SESSION['zone'] = $row['Zonal_id'];
$_SESSION['fullname'] = $row['FullName'];
$_SESSION['loggedin_time'] = time();
$db_sessionid=$row['Session_id'];
$old_sessionid = session_id();
$new_sessionid = session_regenerate_id(true);
$_SESSION['newregid']=$new_sessionid;
$_SESSION['odlregid']=$old_sessionid;
if(!empty($old_sessionid))
{
$query_time=$mysqli->query("UPDATE registation_fst SET Session_id='".$old_sessionid."'WHERE Application_id='".$_SESSION['username']."'");
header("Location:Login-home.php");exit;
} else if($db_sessionid!=$_SESSION['odlregid'])
{
$query_time=$mysqli->query("UPDATE registation_fst SET Session_id ='".$new_sessionid."'WHERE Application_id='".$_SESSION['username']."'");
header("Location:Login-home.php");exit;
}
} else{
$_SESSION['logstu']= "wrong";
header("Location:Login.php");
exit;
}
} else{
$_SESSION['logstu']= "notavail";
header("Location:Login.php");
exit;
}
home page:
<?php
session_start();
ob_start();
print_R($_SESSION);
?>
session values getting changing automatically and reverting back again on refresh
Upvotes: 0
Views: 160
Reputation: 144
welcome to community.try some changing to your ob_start().
maybe write it before session_start or remove it just to know if it is problem.
Upvotes: 0