• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
setcookie natively with PHP

#1
[eluser]davidk43[/eluser]
I'm wondering whether the session library sets up cookies with any write protection or if that's is in anyway possible?

I've a cookie I'm trying to write to and update its expiry time. I'm having some issues with set_cookie so decided to at least get it working with native php code and troubleshoot from there. I can't seem to update the the default 'ci_session' cookie expiry time. Data within it is updated fine but not the cookie's own attributes. To confirm to myself I wasn't going mad I did this:

Code:
setcookie("ci_session",$_COOKIE['ci_session'],time()+1209600,"/");

and then this at the same point on the next line:

Code:
setcookie("ci_session_test",$_COOKIE['ci_session'],time()+1209600,"/");

the test version created absolutely fine, but the default ci_session cookie remained the same. I just can't seem to manipulate the cookies attributes once its been setup by config.

#2
[eluser]CI TaMeR[/eluser]
I don't know if you can update the time on a cookie. But why don't you just read & recreate the cookie?

#3
[eluser]davidk43[/eluser]
That's my point. You don't update a cookie as such, more overwrite it. I wanted to keep tidy and have only the single CI session cookie and add my variables to that. However no matter what I do, I can't seem to overwrite that cookie. This means I have to write my own, which to me is fine, I just use the cookie helper but it would have been nice to work within the session library and keep things tidy. Afterall isn't that the key goal of a framework?

No dig at CI there, I'm loving it and its almost certainly my lack of knowledge that's the problem here! It just means I'm using CI but then within my models I seem to be reverting back to some of my old native PHP coding methods rather than harnessing the framework.

#4
[eluser]Michael Wales[/eluser]
Look at some of the other session management libraries available - they may be able to offer something that will help you out.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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