Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Cookie Monster? (https://www.warriorforum.com/programming/350886-cookie-monster.html)

ECS Dave 19th March 2011 08:47 AM

Cookie Monster?
 
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

wayfarer 19th March 2011 09:04 AM

Re: Cookie Monster?
 
to set cookies, you need to use the setcookie() function

ECS Dave 19th March 2011 09:28 AM

Re: Cookie Monster?
 
I don't need to set the cookie... ;)

Be Well!
ECS Dave

SteveJohnson 19th March 2011 10:05 AM

Re: Cookie Monster?
 
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.

ECS Dave 19th March 2011 10:26 AM

Re: Cookie Monster?
 
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

SteveJohnson 19th March 2011 12:15 PM

Re: Cookie Monster?
 
You're welcome, glad I could hep :)


All times are GMT -6. The time now is 09:30 PM.