I'm new in PHP
and I'm trying to save objects in the $_SESSION
. I've actually read this post, but i need to store something.
I used serialize($myObject)
to put it into the $_SESSION
but when I get it using unserialize()
I get the following message: Warning: unserialize() expects parameter 1 to be string, object given in...
The curious thing is that on my local machine with PHP 5.4 it works. On the host where PHP 5.2 is installed, it doesn't work. I call start_session()
and I instantiate new MyObject()
before calling unserialize....
However ißm a little confused. In some post i read that PHP serialize and unserialize object by itself, so i would not need to call it. Other post says that i MUST call it.
How can i solve this issue?
EDIT: I'm still confused regarding the different behavior of PHP 5.2 and 5.4. The following code prints out different results:
$inner = '';
if (isset($_GET['inner'])){
var_dump(1);
$inner = $_GET['inner'];
} else if (isset($_GET['lang']) === true && isset($_SESSION['inner'])){
$inner = $_SESSION['inner'];
var_dump(2);
} else {
unset($_SESSION['inner']);
var_dump(3);
}
var_dump($inner);
if ($inner == 'editpwd'){
$_SESSION['inner'] = 'editpwd';
} else if ($inner == 'browseparks'){
$_SESSION['inner'] = 'browseparks';
} else if ($inner == 'browsetricks'){
$_SESSION['inner'] = 'browsetricks';
}
by executing it, in both cases the same if-branch is executed, but the value of 'inner' differs.