You are here: Re: [PHP] Setting cookie on first visit « PHP « IT news, forums, messages
Re: [PHP] Setting cookie on first visit

Posted by Richard Lynch on 03/02/05 21:42

Tom Whitbread wrote:
> I am using a cookie to detect what skin a user wants to display. The
> problem is if a user visits the site for the first time the cookie is
> not being set. I am detecting if its being set or not with
>
> if(!isset($_COOKIE['skin'])){ ... }
>
> It's not setting the cookie untill a user refreshes the page once. How
> can I ensure it's set when it hasnt been set before?

Sure it's being set.

That's how you see it when they refresh the page.

$_COOKIE tells you want Cookies the browser *sent* with the request for
the URL.

It's up to you to track within that script what Cookies you are sending
*back* with the answer.

That sounds kinda harsh, and I can see why you'd want it to work the other
way -- as I first did.

But you *need* COOKIES to be what the browser sent initially.

I guess you *could* start doing things like:
<?php
setcookie('var', $value);
$_COOKIES['var'] = $value;
?>
and then it would do what you want...

But you could quickly confuse yourself about what came *in* from the
browser and what you are sending *out* to the browser.

Probably better for you to take a step back and think about how cookies
work, and who sends what where.

--
Like Music?
http://l-i-e.com/artists.htm

 

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

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