+1  A: 

You can use var_dump() to output the session. Something like this

var_dump($this->session);

The set_userdata call looks ok. Are you sure $user_id is set. Because the echo is surley executed but uid isn't set or set to empty string.

Try replacing the echo with

echo ':test_'.$this->session->userdata('uid').'_test:';

Other information helpful for answering

  • What browser are you using?
  • Do you have an underscore _ in your domain name?
  • Are you using CI sessions or some wrapper for native PHPsessions
  • Is the value for uid also lost/not set when you comment out the redirect?


Other suggestions:

  • try redirect('/preferences/index/', 'refresh'); instead of location
  • I'm not familiar with facebook development but is /preferences/index under your control? If yes try removing (if present) $this->load->library(‘session’) and instead load it in autoload.php.
  • try changing $config[‘sess_match_ip’] to `FALSE
  • try setting $config[‘sess_encrypt_cookie’] to FALSE
  • try replacing the use of CI-Session with CI Native session
  • Is UID sensible information if not store it in a cookie. If it matters if it can be spoofed don't.
jitter
So I've done that. When I access the page outside of Facebook, it shows the full expected array: array(6) { ["session_id"]=> string(32) "3ee0c3caea3bf41153ad03f3483c05e5" ["ip_address"]=> string(10) "10.19.32.6" ["user_agent"]=> string(50) "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en" ["last_activity"]=> string(10) "1256249601" ["key"]=> string(5) "value" ["uid"]=> string(8) "userid#" } BUT when I access the same page via Facebook, it only shows the 4 values that CI sets on its own (sessid, IP, usragent, and lastactivity). Anyone know if these are set differently? Stored?
Alex Mcp
I'm using both Safari 4.03 and FF 3.5.3 on OS X. So I just set $user_id = 1234 to try that. It echos within the else when I comment the redirect, but doesn't come back from the session array. :-/
Alex Mcp
And I'm using the CI sessions from a stock download < an hour ago (so I haven't messed up TOO much). And no _ in the domain name. I also did the test surrounding the echo on the redirect page, and it comes out :test__test:
Alex Mcp
Are you using an iframe somewhere? Then maybe the data you set are treated as 3rd party cookies
jitter
The Facebook app isn't setup as an iFrame application.
Alex Mcp
A: 

I didn't solve how to pass session variables from one page to another via Facebook. My solution was simply to call the Facebook API for the user's UID again on each page. Not great programming, but it works alright for me. :-/

Alex Mcp