Sessions don't work

Sessions don't work

Posted by: vld
Posted on: 2008-10-27 09:41:00

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?

Re: Sessions don't work

Posted by: pangea33
Posted on: 2008-10-29 19:29:00

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

In reply to:

// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");


Tags: account idheader locationarray