[PHP] Setting cookie on first visit
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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Setting cookie on first visit
When the user first visits your site, there is no skin in your cookie. Then you can give a default value. And after the user modifies his/her profile, you can set it to the cookie. So I don't think it is a problem of setting cookie. Best regards, Yang Shiqi -Original Message- From: Tom Whitbread [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 02, 2005 5:18 PM To: php-general lists Subject: [PHP] Setting cookie on first visit 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Setting cookie on first visit
The manual detail this issue: http://ca.php.net/setcookie You can't see the cookie until you hit the next page. There is no way view the newly set cookie. Dan Tappin On Mar 2, 2005, at 2:18 AM, 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Setting cookie on first visit
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Setting cookie on first visit
Why not use sessions instead? us2.php.net/session On Wed, 2 Mar 2005 11:42:02 -0800 (PST), Richard Lynch [EMAIL PROTECTED] wrote: 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- The Disguised Jedi [EMAIL PROTECTED] Now you have my $0.02. Or .01 Pounds, .014 Euros, or $0.025 CAN. I'm world-wide BABY! PHP rocks! Knowledge is Power. Power Corrupts. Go to school, become evil Disclaimer: Any disclaimer attached to this message may be ignored. However, I must say that the ENTIRE contents of this message are subject to other's criticism, corrections, and speculations. This message is Certified Virus Free -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php