Page 1 of 1

Need help checking cookies

Posted: Mon Jun 06, 2005 7:08 am
by jolinar
I was wondering if anyone could tell me how to check if a cookie exits. I have tried to do it with the following:

Code: Select all

if(!$_COOKIE[($this->sitedata['cookie']).'user']) {
  	setcookie (($this->sitedata['cookie']).'user',  $this->sitedata['dbuser']);
  		 }
  	
if(!$_COOKIE[($this->sitedata['cookie']).'pass']) {
  	setcookie (($this->sitedata['cookie']).'user', $this->sitedata['dbpass']);
		 }

// Check if the cookie has been created	
echo $_COOKIE[($this->sitedata['cookie']).'user'];
echo $_COOKIE[($this->sitedata['cookie']).'pass'];
but with no success (php4), can anyone help?

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]

Posted: Mon Jun 06, 2005 10:47 am
by Burrito
try using isset()

Posted: Mon Jun 06, 2005 10:48 am
by malcolmboston
as a side note, you cannot check if it exists on the same page you have created it, it takes another page before you can detect it

Posted: Tue Jun 07, 2005 8:53 am
by jolinar
I've tried that and it does have a refresh delay problem. What is the HTML to command a refresh (can that be done, I'm thinking, set a cookie and command the page to reload)

Posted: Tue Jun 07, 2005 9:34 am
by John Cartwright
you can redirect with

header()

Posted: Tue Jun 07, 2005 10:28 am
by Burrito
or also JS' location, or finally a meta refresh....

edit: the problem using header() is that it sends info down to the client and will therefore cause an error unless you're using output buffering

edit2: doh! guess I was wrong, I thought that by sending cookie down, you'd get header already sent probs...(could've sworn I had that prob in the past) apparently not, just tested and it worked fine.