Forum Moderators: coopster

Message Too Old, No Replies

Conditional PHP Cookies; if cookie = 1 do this...

Combining cookies and if conditions

         

JAB Creations

6:47 am on Apr 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've figured out cookies ... now I'm trying to combine them with if conditions.

For cookie 'bandwidth1' I want to echo that it is set to 1 by the cookie to confirm this in the brower through regular html.

My if/else statements don't seem to be working though...heres the code I have now.

<?php
setcookie("bandwidth1","0",time()+2592000,"/");
setcookie("bandwidth2","1",time()+2592000,"/");
setcookie("bandwidth3","2",time()+2592000,"/");
?>

<?php
if (isset($_COOKIE["bandwidth1"])=="1")
echo "Bandwidth is 1!";
else
echo "Bandwidth is unknown";
elsif
echo "Cookie was not set?";
?>

jatar_k

7:07 am on Apr 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why not try

if (isset($_COOKIE["bandwidth1"]))
echo "Bandwidth is 1!";
else
echo "Bandwidth is unknown"

I think you have too many conditions in there

JAB Creations

7:25 am on Apr 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jatar, thanks for the reply...

I was looking around some more and found this...

<?php
echo "$HTTP_COOKIE_VARS[bandwidth1]";
?>

Well not with my variable but you know!

So then I put it in to my if/then statement and it WORKS! *happiness inserted here*

<?php
setcookie("bandwidth1","0",time()+2592000,"/");
?>

<?php
if ($HTTP_COOKIE_VARS[bandwidth1] == "0")
{
echo "IT WORKS!";
}
else
{
echo "Nop sorry";
}
?>

Yours looks strikingly similer. Thanks for your help!