Reply to Cookie array does not work ?

Your name:

Reply:


Posted by Harry Haller on 10/10/05 16:00

Why does the following work:

// (1) Set new cookies
setcookie ("font_type", $type_sel, time()+3600);
setcookie ("font_size", $size_sel, time()+3600);
// (1) Get most recent cookie
$font_type = $_COOKIE["font_type"];
$font_size = $_COOKIE["font_size"];
if (isset($font_type) && isset($font_size))
echo "Found Cookies<br>\n";

But this does not work:

// (2) Set new cookies
setcookie ("font[type]", $type_sel, time()+3600);
setcookie ("font[size]", $size_sel, time()+3600);
// (2) Get most recent cookie
$font[type] = $_COOKIE["font[type]"];
$font[size] = $_COOKIE["font[size]"];
if (isset($font[type]) && isset($font[size]))
echo "Found Cookies<br>\n";

I took (2) from the book Beginning PHP4 (Wrox), page 282-286. I did
(1) myself in an effort to get the book code working.

When (2) is executed the if statement in never true.

Note: $type_sel and $size_sel, in (1) and (2), both have valid values
at the time the cookie is set.

Note 2: I appreciate that I shouldn't be calling my page variables by
the same name as my cookie variables but that is not the problem - it
does not explain why (1) works but (2) does not work.

What am I doing wrong?

[Back to original 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

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