I will explain my problem
From index.php I POST my login and in login.php I store session details (like name) e.g.:
$_SESSION['name'] = mysql_result($res,0,"name");
then I am forwarded back to index.php.
Here I want to show logged-in-user’s name:
echo $_SESSION['name']
and also all names from the DB:
$result=mysql_query($query);
for ($i=0; $i<mysql_num_rows($result); $i++) {
$row = mysql_fetch_assoc($result);
$name =$row['name'];
echo $name;
}
And here comes the problem: after I log in, everything (both user’s name and all names) is displayed correctly. But when I refresh the page echo $_SESSION['name'] shows the last name in the databse == $name instead of the one that was
So I guess I need to clone mysql_result($res,0,"name"); when storing into $_SESSION[‘name’]
Thank you very much
EDIT
the only thing i store in session is the login name. And when the person is logged-in he can see all people from database.
If you are looking to clone an object then you can try the following
From the php documentation it seems that some objects do not support cloning, so if this is the case then you could try the following (again, from comment in php documentation) to do a deep copy
There are some other good points made in the comments of the documentation page which can be found here http://php.net/manual/en/language.oop5.cloning.php
Best regards