Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 19th Mar 2011, 08:47 AM   #1
Is a...
War Room Member
 
ECS Dave's Avatar
 
Join Date: 2007
Location: In the USA...
Posts: 269
Thanks: 65
Thanked 53 Times in 46 Posts
Blog Entries: 8
Default
Cookie Monster?
Share on: 
fb share twitter share gplus share more share

Hi,

Any php cookie reading experts in here?

I cannot figure out why this doesn't work:
Code:
<?php
if($_COOKIE['avalue'=='something']){
echo ' sometext';}
else{
if($_COOKIE=='')
echo ' othertext';}
?>
The cookie "exists", and the "values" are there,
yet the "othertext" is what is being echoed.

Your help is appreciated.

Be Well!
ECS Dave
ECS Dave is offline  
Unread 19th Mar 2011, 09:04 AM   #2
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: Cookie Monster?
Share on: 
fb share twitter share gplus share more share

to set cookies, you need to use the setcookie() function

I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
wayfarer is offline  
Unread 19th Mar 2011, 09:28 AM   #3
Is a...
War Room Member
 
ECS Dave's Avatar
 
Join Date: 2007
Location: In the USA...
Posts: 269
Thanks: 65
Thanked 53 Times in 46 Posts
Blog Entries: 8
Arrow
Re: Cookie Monster?
Share on: 
fb share twitter share gplus share more share

I don't need to set the cookie...

Be Well!
ECS Dave
ECS Dave is offline  
Unread 19th Mar 2011, 10:05 AM   #4
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: Cookie Monster?
Share on: 
fb share twitter share gplus share more share

You have an expression as the array key, and I'm pretty sure that's not what you want.

instead of this:
if($_COOKIE['avalue'=='something']){


use this:
if('something' == $_COOKIE['avalue']){

Also, your second 'if' will not work as expected. $_COOKIE is an array, so testing against '' won't work.

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Unread 19th Mar 2011, 10:26 AM   #5
Is a...
War Room Member
 
ECS Dave's Avatar
 
Join Date: 2007
Location: In the USA...
Posts: 269
Thanks: 65
Thanked 53 Times in 46 Posts
Blog Entries: 8
Default
Re: Cookie Monster?
Share on: 
fb share twitter share gplus share more share

SteveJohnson said
You have an expression as the array key, and I'm pretty sure that's not what you want.

instead of this:
if($_COOKIE['avalue'=='something']){


use this:
if('something' == $_COOKIE['avalue']){

Also, your second 'if' will not work as expected. $_COOKIE is an array, so testing against '' won't work.

------------------------------------------------

I've switched both around, and all seems to work as I wanted it to do...

Dayum Steve, you're f'n awesome... Thanks!

Be Well!
ECS Dave

P.S. It seems (to me) as if the WF "quote" thing is "broken"?
The last few times I've tried to quote someone, it wouldn't
let me post... hmmm
ECS Dave is offline  
Unread 19th Mar 2011, 12:15 PM   #6
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: Cookie Monster?
Share on: 
fb share twitter share gplus share more share

You're welcome, glad I could hep

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Closed Thread


Bookmarks

Tags
cookie, monster


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:50 AM.