CodeIgniter Forums
Shared session - 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: Shared session (/showthread.php?tid=19637)



Shared session - El Forum - 06-13-2009

[eluser]vmuser[/eluser]
Hi!
Can i share a session between two different controllers? One set a value and the other retrieve the value. If yes, how can i do that ? If i can, i don't want store session in database.
At now i only tried to access to the global $CI object, but i can't get any values:


Code:
$CI = & get_instance();
return $CI->session->userdata('token');

Many thanks!


Shared session - El Forum - 06-13-2009

[eluser]jedd[/eluser]
Hi vmuser, and welcome to the CI forums.

If you're using the session library - and loading it automatically in your config/autoload.php file - then you don't need to do the CI =& get_instance() thing. You only need to do that if you're wanting to talk to the super-object from outside a controller. Such as, for example, in a helper.

So, if you are trying to get session data from two different controllers, as you suggest, then it should just work. There's no obligation to store any of this data in a database, if you don't want to.

Try setting some data with a call like this:
Code:
$this->session->set_userdata('bob', 'says hello');

And recovering it in a different controller:
Code:
echo $this->session->userdata('bob');



Shared session - El Forum - 06-14-2009

[eluser]vmuser[/eluser]
I must share the session between a controller and a soap client, but this it doesn't give me back the session probably because it can't set a cookie. How can i do?

Many thanks!


Shared session - El Forum - 06-15-2009

[eluser]vmuser[/eluser]
Anybody can help me ? :-(


Shared session - El Forum - 06-15-2009

[eluser]Dam1an[/eluser]
If you can't create a cookie, then it's a browser permission issue
Make sure you allow your browser to create cookied for your domain

The other alternative is to use native PHP session instead


Shared session - El Forum - 06-15-2009

[eluser]TheFuzzy0ne[/eluser]
It might be worth seeing what happens if you use the session class with the SOAP client. It might require some modification, and it might not work at all, but if you can get it working, I think this will solve your problem.


Shared session - El Forum - 06-15-2009

[eluser]vmuser[/eluser]
[quote author="Dam1an" date="1245078833"]The other alternative is to use native PHP session instead[/quote]

In both case (with native or CI sessions) i must track and report the cookie session; and if i use object serialization?