• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session not working in some pages

#1
[eluser]abhinavp[/eluser]
Hello There,

I came across with some strange problem, I am using codeigniter's session library to maintain user's login status. It is working fine.

But when on one page I am trying to save another session its not working. I am not able to get session's value in another function. I did some this like this:

Code:
$data = array(
        'Title' => $this->input->post(TITLE),
        'Price' => 45,
        'Keywords' => $this->input->post(IMAGE_KEYWORDS),
                                    
        );
        $this->session->set_userdata('imagedata', $data);
        redirect(SOME_WHERE);

After redirecting, I am trying to access 'imagedata' session value but it returns empty.
My session setting in config.php is as follows:
Code:
$config['encryption_key'] = 'jdgfkjsagd jagshdkjsaghdkjagsdj';
$config['sess_cookie_name']  = 'dsfkjdshfkjdshfk';
$config['sess_expiration']  = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name']  = 'ci_sessions';
$config['sess_match_ip']  = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

Please help me.

#2
[eluser]MRosenello[/eluser]
Did you make sure you loaded the session library in the controller for that page? I believe that this has to be loaded on every controller you intend to use the session. Or I believe you can load it by default for everything.

Code:
public function __construct()
{
  parent::__construct();
  $this->load->library('session');
}

#3
[eluser]abhinavp[/eluser]
Hi MRosenello,

Thanks for your reply!

But I defined it in autoload.php. So that on every page i can use sessions.

#4
[eluser]CodeIgniteMe[/eluser]
which part of your codes did you put this?
Quote:
Code:
$data = array(
        'Title' => $this->input->post(TITLE),
        'Price' => 45,
        'Keywords' => $this->input->post(IMAGE_KEYWORDS),
                                    
        );
        $this->session->set_userdata('imagedata', $data);
        redirect(SOME_WHERE);

you can check your session values by echoing
Code:
$this->session->all_userdata();

I think you probably had some errors in your code. note your array, the last comma after your last element

#5
[eluser]abhinavp[/eluser]
Hello CodeIgniteMe,
Thanks for your reply, I dont know about that function to print all session userdata.

But I debugged the code, there is no problem in code, the actual is after saving session, I redirected the page on another one. On redirect page i am not able to access that session values.

#6
[eluser]CodeIgniteMe[/eluser]
what browser are you using?
what is displayed after you put this?
Code:
$this->session->all_userdata();
how do you access your saved sessions?

Code:
$data = array(
        'Title' => $this->input->post(TITLE),
        'Price' => 45,
        'Keywords' => $this->input->post(IMAGE_KEYWORDS),
                                    
        );
        $this->session->set_userdata('imagedata', $data);
        redirect(SOME_WHERE);
you can access them like this
Code:
$this->session->userdata('item');

#7
[eluser]Unknown[/eluser]
Having exactly the same problem. My session data is lost after redirect, but if I call a function within the class without redirecting, everything works well and I can access the session stored data.

Code and Logic is double checked, no errors.
Thanks.

#8
[eluser]CodeIgniteMe[/eluser]
Is it only occurring on a specific browser? What browser are you using?

#9
[eluser]abhinavp[/eluser]
I tested in most common browsers like mozilla, chrome but had no luck.

#10
[eluser]CodeIgniteMe[/eluser]
Have you checked the possibility that you might have unset some or all session data on your script/s?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.