CodeIgniter Forums
Trouble in JavaScript method to get the CI session - 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: Trouble in JavaScript method to get the CI session (/showthread.php?tid=17264)



Trouble in JavaScript method to get the CI session - El Forum - 03-31-2009

[eluser]hahacc[/eluser]
$session_data = array('admin'=>$this->input->post("username"));
$this->session->set_userdata($session_data);
$username=$this->session->userdata(admin);//get the username

There is not a problem in the above code,but when I wanna to get the value of admin with JavaScript method,problem starts to ache my head:

a=get_cookie('admin');//Why nothing?

Why I get the cookie with native CI method,but nothing with the JS method?
PS:I'm not using a database to store the session data.

Thanks for sharing me with this problem.


Trouble in JavaScript method to get the CI session - El Forum - 03-31-2009

[eluser]xwero[/eluser]
admin is not the name of the cookie. If you didn't change it in the config.php file ci_session is the cookie name.


Trouble in JavaScript method to get the CI session - El Forum - 03-31-2009

[eluser]hahacc[/eluser]
Thank for replying.

But,as you say,I tried:

getCookie('ci_session');

But nothing I got later,too.

And besides,I can not find the ci_session cookie in C:\Documents and Settings\Administrator\Cookies.

If I set several cookies in a page,how to get each of them?(for there is only one cookie,namely ci_session)

My question is somehow too fool,yes?
But it really troubles me.


Trouble in JavaScript method to get the CI session - El Forum - 03-31-2009

[eluser]hahacc[/eluser]
Or can I get it via:

In controller:
$this->load->helper('cookie');

In view:
echo $a=get_cookie('ci_session');