You are here: Re: newbie simple problem with cookie « All PHP « IT news, forums, messages
Re: newbie simple problem with cookie

Posted by Martin Jay on 03/30/06 03:31

In message <85vWf.38278$u31.10281@newsfe2-win.ntli.net>, David Graham
<david.graham18@ntlworld.com> writes

>Why does my cookie not get set?
>I just get "Your last visit was - " and nothing else

><?php
>//Calculate 60 days in the future
>//seconds * minutes * hours * days + current time
>$inTwoMonths = 60 * 60 * 24 * 60 + time();
>setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);
>?>

setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);

should be:

setcookie("lastVisit", date("G:i - m/d/y"), $inTwoMonths);

Note the quotes around "lastVisited."

Also, cookies must be sent to the browser before any other output. The
PHP manual says:

"Like other headers, cookies must be sent before any output from your
script (this is a protocol restriction). This requires that you place
calls to this function prior to any output, including <html> and <head>
tags as well as any whitespace."
--
Martin Jay

 

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

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