Welcome Guest, Not a member yet? Register   Sign In
Question about Sessions ...
#1

new to codeigniter. been working/playing for about 3 weeks. in my spare time. to all you experienced users, I ask your indulgence and request that you be gentle with the newbie asking questions.

i have several controllers defined for handling menus on a screen in an app i'm writing to learn this stuff. this is now a very basic general ledger system.

I have clients, transactions, reports, general ledger, options, utilities defined as menus and as a result, each one a controller.

i want to be able to have specific items that are constant (not constants) in the system available to all parts of the system. for example, a client number. and data about that client. in other php apps I've developed, I would store that information in the session variable. so figured I would use the session helper. but it appears that the session stuff is reinitialized each time a new controller is instantiated. is that the case? is there a means to change that if it is the case?

i realize I'm being vague, but i'm still at the point where I'm not sure that what I'm saying is sensible. and i'm still trying to make heads or tails of it all.

any alternative suggestions?

OM...

----------------------------

And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Reply
#2

(11-11-2014, 03:09 PM)ozzy mandiaz Wrote: new to codeigniter. been working/playing for about 3 weeks. in my spare time. to all you experienced users, I ask your indulgence and request that you be gentle with the newbie asking questions.

Welcome!

(11-11-2014, 03:09 PM)ozzy mandiaz Wrote: i want to be able to have specific items that are constant (not constants) in the system available to all parts of the system. for example, a client number. and data about that client. in other php apps I've developed, I would store that information in the session variable. so figured I would use the session helper. but it appears that the session stuff is reinitialized each time a new controller is instantiated. is that the case? is there a means to change that if it is the case?

Sessions are shared across an entire application for one user session and are not cleared between page changes, except for flashdata which is only good for one use.
- Ben Edmunds
 CI Counsel Member  |  @benedmunds
 Ion Auth  |  Securing PHP Apps
Reply
#3

Hi, ozzy. Welcome to Codeigniter and its forums.

Just to clarify, there's no actual session helper. There is a session class, and all you have to do to use it is autoload it or declare it in your class constructor like this:
PHP Code:
$this->load->library('session'); 

The Codeigniter sessions don't use the PHP sessions, so you don't have to do any session_start() like you do in PHP. Merely loading the library is enough.

In response to your question, no, Codeigniter does not automatically reinitialize sessions when it instantiates a new controller. It first checks to see if the existing session has expired. Open the file config.php in your application/config folder and look for 'sess_expiration.' It comes set by default to 7200 seconds, which is two hours.

I don't know if or how this would affect things, but check also for 'encryption_key.' The manual says you must set it, and you can set it to whatever string you want.

Aside from that, I don't know what else it could be. Huh
Reply
#4

hellol all, i'm a new member here! please take care of me Big Grin i wanna learn about CI more and more hehe

(11-11-2014, 05:57 PM)benedmunds Wrote:
(11-11-2014, 03:09 PM)ozzy mandiaz Wrote: new to codeigniter. been working/playing for about 3 weeks. in my spare time. to all you experienced users, I ask your indulgence and request that you be gentle with the newbie asking questions.

Welcome!

(11-11-2014, 03:09 PM)ozzy mandiaz Wrote: i want to be able to have specific items that are constant (not constants) in the system available to all parts of the system. for example, a client number. and data about that client. in other php apps I've developed, I would store that information in the session variable. so figured I would use the session helper. but it appears that the session stuff is reinitialized each time a new controller is instantiated. is that the case? is there a means to change that if it is the case?

Sessions are shared across an entire application for one user session and are not cleared between page changes, except for flashdata which is only good for one use.
Reply
#5

(11-11-2014, 03:09 PM)ozzy mandiaz Wrote: but it appears that the session stuff is reinitialized each time a new controller is instantiated. is that the case? is there a means to change that if it is the case?

While the sessions shouldn't be regenerated each time, I have run into situations where a cookie-based session within CI wasn't working. I was never able to exactly track down why, but I didn't try to hard either.

In every instance that I recall, changing sessions to be stored in the database resolved that issue. (Looks like the user guide doesn't have named anchors so just scroll to the bottom of the page and look for the secion Saving Session Data to a Database).
Reply
#6

(11-11-2014, 07:28 PM)kilishan Wrote: While the sessions shouldn't be regenerated each time, I have run into situations where a cookie-based session within CI wasn't working. . . . In every instance that I recall, changing sessions to be stored in the database resolved that issue.

Wow, I didn't know that. But in case storing sessions in the database is more complicated than someone wants to do things, here's how to set up a custom class that uses the regular PHP sessions.

http://www.moreofless.co.uk/using-native...deigniter/

And of course, you don't even have to use a library. You can use regular PHP session code as usual. Just put the session_start() in your constructor, and then add data to the $_SESSION variable in the usual way ($_SESSION ['customer'] = 'Joe Smith')
Reply
#7

Thanks to you all for your suggestions. greatly appreciated.

I'm spending tonight and tomorrow working with the database session handling.
OM...

-------------------------
And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.
Reply
#8

(11-11-2014, 07:05 PM)ella Wrote: hellol all, i'm a new member here! please take care of me Big Grin i wanna learn about CI more and more hehe

Sure, Ella! Welcome! Why don't you drop by the Lounge forum and tell us what your programming experience is and how much you know about PHP and stuff like that?

As for Codeigniter, I would suggest you start with a simple application, even something as simple as an address book, and then ask questions as you go along. Smile
Reply
#9

i know that using cookies to store the session stuff imposes a 4K limitation; does anyone know if the database storage imposes the same 4K or is it larger?

I also see that the userdata field in the table is a text field. would it make more sense to change that to a blob (assuming mysql)? or should i just use it the way it is?

thanks in advance...
OM...

-------------------------
And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.
Reply
#10

The database doe's not have a 4kb limit, you can use text, mediumtext and largetext for the user_data field.

The new CI 3.0 session uses blob for the user_data field.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB