Assigning global var to session variable?
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.