Reputation: 1281
I am trying to use a session variable like this:
$string = 'abc';
$_SESSION[$string];
But I get access if i use it like this:
$_SESSION['abc'];
But I get always an error like this:
Notice: Undefined index: abc
Any ideas to solve my problem? :/
Upvotes: 0
Views: 79
Reputation: 8701
Simply calling
$string = 'abc';
$_SESSION[$string];
is not enough. It's only becomes available when you assign some value to it.
$string = 'abc';
$_SESSION[$string] = 'test';
echo $_SESSION['abc']; //test
Also, make sure that session_start()
is called on a page you're accessing it.
Upvotes: 1