0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
develth
  • 771
  • 8
  • 32
  • possible duplicate of http://stackoverflow.com/questions/17242346/php-session-lost-after-redirect – Latheesan Apr 02 '14 at 14:00
  • 1
    have you used `session_start()` on the top of every page that you want to get the session values. – user3293145 Apr 02 '14 at 14:01
  • why are you setting header("Status: 301 Moved Permanently") ? – Radu Apr 02 '14 at 14:01
  • yes, i´m using session_start(); on top of the page. – develth Apr 02 '14 at 14:02
  • my problem is not to have a NULL Session - but the Session VALUES are null. if i output session it outputs still the keys etc. but the values are null. – develth Apr 02 '14 at 14:14
  • Why aren't you using the TYPO3 User Authentication to login proper frontend users? If you do so, you have the permission management on content and pages and in Extbase extensions included without the need to write own security stuff. – lorenz Apr 02 '14 at 15:54
  • because i have to check in another external service for existing user and "fake" logon them into TYPO3. - it got solved by user3293145 suggest, there was a call between the redirects that overwrote the data. solved! – develth Apr 02 '14 at 17:23

2 Answers2

1

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.

Radu
  • 1,159
  • 3
  • 22
  • 40
0

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 ...?

Sysout
  • 91
  • 6
  • i do this rederict just for debuggin. i output it in my console. adding session_name and session_id doensn´t help - all values still NULL. It seems like it doesn´t have problems on finding the Session, the session itself exists with the keys - but the values are null. – develth Apr 02 '14 at 14:13
  • OK. The session-id of the request is used by your server to locate a local sessionfile at the servers filesystem. This sessionfile contains the sessiondata. So check if your server uses another sessionfile for the targeturl. Have the redirected URL another (sub)domain then the Source-URL? – Sysout Apr 03 '14 at 10:42