You are here: Re: Heeeeeeeeeeeeeeeeeeeeeelp ! why this programme doesn't work? « PHP Programming Language « IT news, forums, messages
Re: Heeeeeeeeeeeeeeeeeeeeeelp ! why this programme doesn't work?

Posted by Mladen Gogala on 06/14/06 14:56

Carl Anatorian wrote:

> Another one :
> <?php
> if($_COOKIE['hello'] != "world") {
> $result = setcookie("hello","world",60*10);
> }
> ?>
> <html>
> <body> <?php
> if(isset($_COOKIE['hello'])) {
> echo "hello !";
> }
> ?>
> </body>
> </html>
>
> I think it will show "hello !" when I access it the second time, but it
> never.Why? I don't disable my browser's cookies.

Carl, setcookie returns boolean, so it would be prudent to check
whether it has actually happened. You should add something like:
if (!$result) { die("Better luck next time"); }
Second, cookies will NOT be sent if the HTML headers have already been
sent. Your heading (<html>) makes sure that they have been sent, so your
cookie will probably not be sent. You should do something like
<?php ob_start(); ?> before the HTML header.

--
Mladen Gogala
http://www.mgogala.com

 

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

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