radalin Posted December 4, 2006 Share Posted December 4, 2006 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 More sharing options...
HuggieBear Posted December 4, 2006 Share Posted December 4, 2006 Can you post your code?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/29384-session-variable-getting-lost/#findComment-134792 Share on other sites More sharing options...
radalin Posted December 4, 2006 Author Share Posted December 4, 2006 [code]session_start();echo $_SESSION['SID'] ; //echo no1if ( ! $_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. Link to comment https://forums.phpfreaks.com/topic/29384-session-variable-getting-lost/#findComment-134802 Share on other sites More sharing options...
radalin Posted December 6, 2006 Author Share Posted December 6, 2006 I checkes on somewhere else and I saw that my code worked perfectly. So it should be somethin about the php settings. Which setting should I check? Link to comment https://forums.phpfreaks.com/topic/29384-session-variable-getting-lost/#findComment-136251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.