Need help checking cookies

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
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Need help checking cookies

Post 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]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try using isset()
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Post 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)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you can redirect with

header()
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply