Welcome Guest, Not a member yet? Register   Sign In
newbie ask : cookie
#1

[eluser]Unknown[/eluser]
I'm new in code igniter. I'm so glad i made it, but i have little problem. Here is my code in a simple function/action in a controller.

$this->load->helper('cookie');

$cookie = array(
'name' => 'test',
'value' => 'The Value'
);
set_cookie($cookie);
echo get_cookie('test');

i can't get it working. :roll:
#2

[eluser]GSV Sleeper Service[/eluser]
get_cookie won't work until after you've refreshed the page.

cookies are sent in the header, the set_cookie() will not be effective until the next lot of headers are sent to your browser.
#3

[eluser]xzela[/eluser]
thanks guys.

I was having issues with setting and getting cookies, but this thread shed some light on the subject. I wasn't aware that cookies are only available after the next page refresh.

Can we add this information to the user guide? It might be useful for others.
#4

[eluser]Thorpe Obazee[/eluser]
[quote author="xzela" date="1244158377"]thanks guys.

I was having issues with setting and getting cookies, but this thread shed some light on the subject. I wasn't aware that cookies are only available after the next page refresh.

Can we add this information to the user guide? It might be useful for others.[/quote]

It's how PHP works. No need to add it.

From php.net

Quote:Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays.
#5

[eluser]Colin Williams[/eluser]
bargainph's right. CI docs don't need to explain PHP. It's a prerequisite.




Theme © iAndrew 2016 - Forum software by © MyBB