![]() |
Session not storing data across functions? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Session not storing data across functions? (/showthread.php?tid=27033) |
Session not storing data across functions? - El Forum - 01-29-2010 [eluser]fireproofsocks[/eluser] I'm going nuts... I'm missing something. This works: $this->session->set_userdata('email', 'xyz' ); print "email: " . $this->session->userdata('email'); But when I separate the functions by setting the email in one controller, then redirecting to a new controller via header(), the email comes up blank when I try to read it in the 2nd controller function. What's going on? Session not storing data across functions? - El Forum - 01-29-2010 [eluser]theprodigy[/eluser] are you loading session in both controllers before trying to set or retrieve the values? $this->load->library('session'); Session not storing data across functions? - El Forum - 01-30-2010 [eluser]fireproofsocks[/eluser] I've got the session library referenced in my autoload file, but I tried it manually loading the session library too... the results are the same: session data does not persist across page loads. Session not storing data across functions? - El Forum - 01-30-2010 [eluser]theprodigy[/eluser] try doing it without redirecting (set the session variable, then output a view with a link to the next controller). Maybe it's a time issue, maybe you are being redirected before the system has a good chance to set the variable, so when you output it, it actually has no data stored in it. do you have logging set to a good level? Is there anything in the logs about it? Session not storing data across functions? - El Forum - 01-30-2010 [eluser]fireproofsocks[/eluser] It's not a timing issue... I tried setting it without redirecting, then manually going to the next controller, but the data was gone. I haven't looked at the logs to be honest... can you tell me where to look and which variables to tweak? Session not storing data across functions? - El Forum - 01-30-2010 [eluser]theprodigy[/eluser] configuration of log settings can be found in: application/config/config.php There is a variable called: $config['log_threshold']. The instructions are right above it. The default place to find your logs are: system/logs but this can be changed in application/config/config.php as well (the variable right below $config['log_threshold'] is $config['log_path']). And just for debugging purposes, make sure there is no typos in your setting or retrieving (like setting email, but retrieving emial). Also make sure you are echoing (or printing) the retrieval, and not just retrieving it. Session not storing data across functions? - El Forum - 01-31-2010 [eluser]Colin Williams[/eluser] You probably have your cookie settings incorrect and the browser is refusing to save the cookie. But regardless of that, the Session is not the place to store data you want to move around your app, so I'd rethink your approach Session not storing data across functions? - El Forum - 01-31-2010 [eluser]fireproofsocks[/eluser] I enabled logging, but nothing was written to the log file... not sure if there are permission errors on the log files, but it's possible. I've seen a few other weird things on this client's server, so I'm not too surprised if this is another one of them. Thanks Colin. I'm not sure if I follow your reasoning, and I think I'm getting confused by CI's implementation of its "sessions". The only thing I'm attempting to store in the session are the following: 1. Whether or not the user has successfully logged in (TRUE | FALSE) 2. Whether or not the user has agreed to the latest terms and conditions (TRUE | FALSE) 3. The user's id (his email address in this case) If there's another way to code this, I'm not seeing it. We can't rely on cookies because the visitors may have them disabled, so the only thing we use cookies for is for optionally remembering the user's info to pre-populate the login form when they return to the site. That's only an "ease of use" situation; the site is designed to function without cookies. When I think of a session, I think of the data being stored on the server (usually in the temporary directory configured in the php.ini file: session.save_path ). When I think of a cookie, I think of data being stored on the user's computer, but your reply seemed to infer that CI writes data to the user's cookies with its session library (which is a confusing bit of nomenclature). Is that correct? Is CodeIgniter's solution to load-balanced servers to write session info as cookies OR to use the database configured in the config/config.php file? That makes some sense, but I can see why there might be problems with it.... actually, this is probably exactly why I was having problems with this... one of my browsers is set to ignore cookies, which would get me into trouble when the session library actually tried to write one... since I thought I was writing SESSION information, it never crossed my mind that COOKIES may have been involved. I think I'll have to do this with straight PHP instead of using CI's session library. Session not storing data across functions? - El Forum - 01-31-2010 [eluser]Colin Williams[/eluser] Sounds like you haven't read the Session page in the docs Session not storing data across functions? - El Forum - 01-31-2010 [eluser]fireproofsocks[/eluser] I skimmed it... obviously I missed the part where a session is really a cookie. My bad. But I have a great idea for a new CI library... |