php - Session value is not being updated in CodeIgniter -


i'm wondering if did found bug or amount of hours programming might not let me see obvious?

here's example of code:

class home extends ci_controller {     public function __construct()     {      }      public function edit()     {         // prints: john         print_r($this->session->userdata('name'));          $this->load->view('home/edit');     }      public function ajax_edit()     {         $this->session->userdata('name', 'obama');          // prints: obama         print_r($this->session->userdata('name'));     } } 

i call function ajax_edit ajax, , print "obama", correct. after that, refresh page (to edit function) , output of name "john".

why in god's heaven isn't session updated value "obama"? seems after refreshing resets or , backs old value "john".

the problem not using right methods.

in order set new information ci session, need use set_userdata(), , in order retrieve, or check, whats in session use userdata("key").

solution: rewrite ajax_edit() method code so:

public function ajax_edit() {     $this->session->set_userdata('name', 'obama');      // prints: obama     print_r($this->session->userdata('name')); } 

source: http://www.codeigniter.com/user_guide/libraries/sessions.html#adding-session-data


Comments