Sessions don't work

software development

#1

Sessions don’t work…

—login.php—

session_name();
session_start();
session_register(“account_id”, “account_nick”);
session_encode();
header(“Location: index.php”);

—index.php—

session_start();

print_r($_SESSION);

=== Result = Array ( [account_id] => [account_nick] => )

What’s going on?


#2

The functionality is working as designed. In order to register account_id and account_nick with values, you have to assign those variables values first. You’re simply registering two empty session variables and the output of print_r shows that they have in fact been set.

You either need to set $account_id and $account_nick to something first or set them without the session_register function like this: $_SESSION[“account_id”] = “value”; I would suggest that anyway because session_register has been deprecated.

From: http://us.php.net/session_register

[quote]// Use of session_register() is deprecated
$barney = “A big purple dinosaur.”;
session_register(“barney”);[/quote]