Assigning global var to session variable? I want to assign the user name to a SESSION variable, yet this is not working.

$_SESSION['loveleytest'] = $user;
$_SESSION['thelovelytest2'] = $user-&gt;name;

What should I do?
For assigning user_name to a session variable you would directly do something like

global $user;
$_SESSION['thelovelytest2'] = $user-&gt;name;


I think the issue with your code may be:


It is not able to retrieve the global $user variable.
You might not have defined the global $user variable.
Because you did $_SESSION['loveleytest'] = $user, thats why the issue is there.


I am also curious to know which was the exact issue.