Jump to content

Recommended Posts

Hi,
I'm using session variables for my member system. I got a session id which is kept as a session variable then have a session table etc. I get user info throught this session id. But the thing is in my local, session variables not saved! They are lost and every time I refresh the page they are recreated. There is a check, if there is no session then create a one, else use the existing one. I should be missing something in the php.ini or something I'm not sure about it.

Any idea why can this happen? I have wamp 1.6.4 installed on my computer with Mysql 5 and PHP 5 options.

Thank you for your time
Link to comment
https://forums.phpfreaks.com/topic/29384-session-variable-getting-lost/
Share on other sites

[code]
session_start();
echo $_SESSION['SID'] ; //echo no1
if ( ! $_SESSION['SID'] )
{
$_SESSION['SID'] = md5( uniqid(rand(),1) );

setSession( $_SESSION['SID'] ) ;
}
echo $_SESSION['SID'] ; //echo no2
[/code]

and the setsession function is

[code]
function setSession($sid = "")
{
if ($sid == "")
{
$_SESSION['SID'] = md5( uniqid(rand(),1) ) ;
$sid = $_SESSION['SID'] ;
}

$this->db->connect() ;

if (MDB2::isError($this->db))
die($this->db->getMessage());

$query = "SELECT session_id FROM sessions WHERE session_id = '" . $sid ."' ";

$result = $this->db->queryOne($query);

if (MDB2::isError($result))
die($result->getMessage());


//If this sid is previously set before then we have already have a value
//for that user...
if ( $result == $sid )
return 0 ;

//And if such sid does not exists
$query = "INSERT INTO sessions (session_id,session_start,session_last_activity_date,session_ip,session_logged_in,user_id) VALUES ('$sid','" . date('m-d-Y H:i:s') ."','" . date('m-d-Y H:i:s') ."','". $_SERVER['REMOTE_ADDR'] ."','-1','-1')";

$this->db->_doQuery($query);

if ( MDB2::isError($this->db) )
die($this->db->getMessage());

$this->db->disconnect() ;

return 1 ;
}
[/code]

The problem is at echos. While first one does not print anything the second one does. (I assume you already entered to the site and clicked a few links.). setSession() function is called and then a new session id created. As the session id changes all the time, I can't reach to the right session row. I wonder why the session variables are lost.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.