1

I want to assign the user name to a SESSION variable, yet this is not working.

$_SESSION['loveleytest'] = $user;

$_SESSION['thelovelytest2'] = $user->name;

What should I do?

  • 2
    I do not see a point in assigning global varaibles to session. You have access to global $user already at every page load. – arpitr Jun 3 '15 at 21:05
0

For assigning user_name to a session variable you would directly do something like

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

I think the issue with your code may be:

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.