You are here: Re: $_COOKIE variable is always empty « All PHP « IT news, forums, messages
Re: $_COOKIE variable is always empty

Posted by J.O. Aho on 03/03/07 23:04

Seansan wrote:
> Hi,
>
> When I run the following in PHP then two cookies are set.
>
> ini_set('session.name', 'session-1');
> session_start();
> setcookie('session-2', '');
>
>
> Both cookies are being sent to the client, and then to the server (I am
> sure), but they are not available in $_COOKIE (this array is empty).
>
> Why and how can the $_COOKIE variable be empty - this is getting
> frustrating. Am I missing something? All other global variables are
> available normally, only $_COOKIE is always empty.

Even if sessions many times are cookies, they don't use the $_COOKIE
array, but $_SESSION, as you want to be able to access a session the
same way no matter if it's embedded into url or as a cookie.

I suggest you take a look at

http://www.php.net/manual/en/ref.session.php
http://www.php.net/manual/en/function.session-start.php

to see how session works


setcookie() may require you to specify all the arguments, seems to be a
long lived msie bug that makes it to not save a cookie and also keep in
mind that you can't access a cookie value until the script after the one
where you created (the same applies to value changes).


--

//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация