...

View Full Version : First cookie wins



steveorg
11-14-2007, 08:12 PM
I have a working cookie setting script. I don't want to replace an existing unexpired cookie. How can I start the script to test for the existence of an unexpired cookie, and then not set a cookie if an unexpired cookie exists? I don't really know PHP, so all help is appreciated.

Thanks,
Steve

Inigoesdr
11-14-2007, 08:26 PM
if(!isset($_COOKIE['cookiename']))
{
setcookie('cookiename', 'data');
}

steveorg
11-14-2007, 09:08 PM
Thank you Inigoesdr!

Like I said I don't know PHP, so forgive me if this questions seems basic. It seems that the logic sets a cookie if a cookie exists. I want the opposite. Am I misreading this? If I am misreading this, should I replace setcookie('cookiename', 'data') with my cookie script?

Steve

Inigoesdr
11-15-2007, 01:25 AM
It seems that the logic sets a cookie if a cookie exists. I want the opposite. Am I misreading this?
Yes, you're misreading it. The exclamation point in front of the function tells the logic to look for the opposite.

If I am misreading this, should I replace setcookie('cookiename', 'data') with my cookie script?
Yes.

steveorg
11-16-2007, 02:47 PM
This is perfect. :thumbsup: Thanks so much for your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum