Welcome Guest, Not a member yet? Register   Sign In
Problems with $_SESSION in application/libraries/ class
#1

[eluser]sherbo[/eluser]
Hi,

One of my custom application/libraries/ classes is placing stuff in $_SESSION. However, it seems to be out of sync with the $_SESSION in my CI controllers.

Is there any special syncing I need to do when referencing $_SESSION in my library class?

cheers,
Sherban
#2

[eluser]mironcho[/eluser]
Do you have session_start() somewhere in your code (or session.auto_start set to true/1 in your php configuration)?
Why don't you use CI Session Smile
#3

[eluser]llbbl[/eluser]
ci session works pretty good. I have used sessions in the past to store form data on Multi-page forms so you don't get the resubmit POST dialog box. Not sure if CI sesssions can do this, but I guess you could do the multipage form using jQuery/javascript these days huh.
#4

[eluser]sherbo[/eluser]
mironcho,

Yes, I call session_start() at the beginning of each of my controller's view functions.

I'm still trying to figure out why there are so many different varieties of sessions.

The reason I'm using $_SESSION instead of CI session is in case we ever switch to another framework. I won't have to refactor session management code if I use $_SESSION.

cheers,
Sherban
#5

[eluser]mironcho[/eluser]
Probably I gave you incorrect answer. You should call session_start() before first usage of $_SESSION array.
So if you use $_SESSION in library first, you must call session_start() there.
#6

[eluser]sherbo[/eluser]
I missed a placement of session_start() somewhere in my code. After I put it in, the problem was fixed.

Curses! I loathe placing session_start() every time I need to use the $_SESSION!

Is there a best practice and/or configuration setting to make $_SESSION available everywhere in my app?
#7

[eluser]llbbl[/eluser]
Session Class

I have used this guy's session class in the past with some success. You might give it a try!
#8

[eluser]Rick Jolly[/eluser]
[quote author="sherbo" date="1194509419"]
Is there a best practice and/or configuration setting to make $_SESSION available everywhere in my app?[/quote]
You could place the session_start() in the constructor of a parent/base/application controller, but it's probably best to use a class that wraps the php native sessions. This is a popular choice: http://codeigniter.com/wiki/Native_session/. No dependencies on CI (if you remove the log_message function). Also, it has flash data and session regeneration.




Theme © iAndrew 2016 - Forum software by © MyBB