develth
develth

Reputation: 782

PHP: Session value null after redirect

I do an AJAX call to login my TYPO3 Users. Everything doing well. I also write some session values. After successfull login i have this session:

array(10) {
    ["loggedin"]=>
          int(1)
    ["user"]=>
          string(15) "Thomas Helmrich"
    ["kdnr"]=>
          string(3) "N/A"
    ["email"]=>
          string(15) "Thomas Helmrich"
    ["bereich"]=>
          string(3) "all"
    ["name"]=>
          string(0) ""
    ["intern"]=>
          int(1)
    ["nickid"]=>
          string(4) "4734"
    ["chatadmin"]=>
          int(1)
    ["spezialforum"]=>
          int(0)
}

but after the redirect like e.g.

header("Status: 301 Moved Permanently");
header("Location:".$redirect_url);
exit();

The Values are null

array(14) {
  ["loggedin"]=>
  NULL
  ["user"]=>
  NULL
  ["password"]=>
  NULL
  ["kdnr"]=>
  NULL
  ["email"]=>
  NULL
  ["bereich"]=>
  NULL
  ["name"]=>
  NULL
  ["chatadmin"]=>
  NULL
}

I currently don´t know why the values get null´d

Thanks

Upvotes: 0

Views: 931

Answers (2)

Sysout
Sysout

Reputation: 101

Try something like this (add Session-ID to the URL):

header("Status: 302 Found");
header("Location:".$redirect_url.'?'.session_name().'='.session_id());
exit();

This is only necessary if your client don't allow cookies.

BUT: Really have to make your redirection "permanently"? Maybe, a 302 do it better ...?

Upvotes: 0

Radu
Radu

Reputation: 1177

Session ID is not passed with Location header even if session.use_trans_sid is enabled. It must by passed manually using SID constant.

From: http://www.php.net/manual/en/function.header.php last note.

Upvotes: 1

Related Questions