How to test if cookie is already set?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

How to test if cookie is already set?

Post by ljCharlie »

I have a page that when the user logged in, I set the cookie. However, I couldn't figure out how to test if the cookie is already set. If the cookie is alredy set for that user, then do not set the cookie again.

Any suggestion is much appreciated.

ljCharlie
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Code: Select all

if(!isset($_COOKIE)){
      set_cookie();
   }
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Thank you very much...I'll give that a try. I thought it would be something harder.

ljCharlie
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Oh, by the way, one more question. Is the $_COOKIE something I manually have to declared or is that part of the PHP reserved word to test if cookie is set?

ljCharlie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

predefined superglobal
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Code: Select all

<?php
print "<pre>"; 
print_r($_COOKIE); 
print "</pre>"; 

?>
see all the cookie values that are stored
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Thanks!

I'll give that a try.

ljCharlie
Post Reply