![]() |
Session between controllers - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Session between controllers (/showthread.php?tid=24148) |
Session between controllers - El Forum - 11-01-2009 [eluser]ping timeout[/eluser] Hello, I started an application with CI. I've made Controllers for the registration page, activation, login and user pages. In my controllers/login.php function index(); I have someting like: Code: //code Code: <h1>Hello <?php echo $this->session->userdata('username'); ?></h1> Code: function _is_logged_in() I tested a few times, with both database session and cookie sessions, and with bot autoload session library and manual load... What can I do? Session between controllers - El Forum - 11-01-2009 [eluser]Ben Edmunds[/eluser] Try setting the session variables individually and then echoing directly after to see if it's even getting set at all. Session between controllers - El Forum - 11-01-2009 [eluser]ping timeout[/eluser] I've changed my code: Code: //$username = array('username' => set_value('username'), 'logged_in' => TRUE); And if I let this: Code: //echo $this->session->set_userdata('username'); I've tested with: Code: echo $this->session->set_userdata('username'); Session between controllers - El Forum - 11-01-2009 [eluser]Ben Edmunds[/eluser] OK, just do this in your controller Code: $this->session->set_userdata('username','test'); What do you get? Session between controllers - El Forum - 11-01-2009 [eluser]ping timeout[/eluser] I get: test - logged_in=1 Session between controllers - El Forum - 11-01-2009 [eluser]Ben Edmunds[/eluser] Problem solved. Looks like set_value('username') doesn't contain anything and instead of checking for logged_in == TRUE just check for logged_in: Code: function _is_logged_in() Session between controllers - El Forum - 11-01-2009 [eluser]ping timeout[/eluser] NO, it's not because of set_value(‘username’) - because it has the right value( no form validation errors) and anyway I changed the code to: Code: $this->session->set_userdata('username','test'); Code: <h1>Hello <?php echo $this->session->userdata('username'); $username=$this->session->userdata('username'); ?></h1 Code: function user() Code: <h1>Hello <?php echo $this->session->userdata('username'); $username=$this->session->userdata('username'); ?></h1 In personal I see Hello test, when I click on User, I get only Hello. I don't get it, anything (captcha, email, form validation...) works fine till here... Also noticed something: I've changed my code and it looks like this: Code: class Personal extends Controller 1. index.php/personal shows views/login 2. index.php/personal/ shows views/login 3. index.php/personal/user shows views/personal_user only for IE, in FF it shows login 4. index.php/personal/user/ shows views/login Session between controllers - El Forum - 11-01-2009 [eluser]InsiteFX[/eluser] Change logged_in = 1 not true logged_out set to 0 Enjoy InsiteFX |