Problems with cookies |
[eluser]Dani[/eluser]
Hi, I have some trouble with saving cookies. I am trying to save form data into cookies. For this I have the following in my controller where the form is returned to: Code: print_r($this->input->post()); Output of this is: Code: Array ( [currency] => USD [unit_size] => 40 [adress] => some street [submit] => Save ) - Google Chrome debugger -> Resources -> cookies -> localhost just displays "This site has no cookies". - I have tried switching to 127.0.0.1 both in the url and in the config.php. - I have tried setting up dev.livesite.com and setting cookie domain to .livesite.com in config.php as described here http://stackoverflow.com/questions/39021...-localhost Any suggestions?
[eluser]Aken[/eluser]
Are you using sessions already? If so, why not save it as session userdata instead?
[eluser]Dani[/eluser]
I don't use sessions, not explicit at least. The reason I prefer cookies is that I want to save user settings, and session expires as soon as you close your browser. I could ofc save settings to db, but that would require more coding and load time as I then would have to set up a multiuser system (user table, etc).
[eluser]tonyurso[/eluser]
Usually you wont see cookies on the same page that you set them.
[eluser]Dani[/eluser]
[quote author="tonyurso" date="1354657636"]Usually you wont see cookies on the same page that you set them.[/quote]So then the cookies should be set when navigating to other pages on the site? They are not.
[eluser]CroNiX[/eluser]
You can't set a cookie and immediately read it without a refresh. The cookie doesn't get written until the final output is sent to the browser since it's transmitted in the headers of the request...
[eluser]Dani[/eluser]
I have tried to navigate to other pages and refresh and refresh. Still no cookies are set.
[eluser]CroNiX[/eluser]
Post all cookie values from your config settings. As a side, it would be much better to serialize (or json encode) your post array one time and store that in a single cookie rather than an individual cookie for each post value. Then unserialize it when reading it back.
[eluser]Dani[/eluser]
config.php (@localhost) Code: $config['sess_cookie_name'] = 'ci_session'; Ok, I'll look into serializing. |
Welcome Guest, Not a member yet? Register Sign In |