Jump to content

Reading cookies


realjumper

Recommended Posts

Hi,

I set a cookie according to an 'if' 'else' situation something like this...

[code]
if ($cpd_id == $doo)
{
setcookie ("answer", "Yes - $row2[compound] is the correct answer");
}

else{
setcookie ("answer", "Sorry - $row2[compound] was the correct answer");
}

echo $_COOKIE["answer"];
[/code]

What I would like to do is colour the text according to the answer.....red for a wrong answer, green a correct answer.

The variable $row2[compound] will always be different, so is there a way to detect a single word in the cookie, say, 'Yes' and then colour the answer in a green font? Very crudely, this is what I would like to do if it's possible....

[code]
if ($_COOKIE["answer"] contains 'Yes' as the first 3 characters)
{
echo <p style='color:green'>$_COOKIE["answer"]</p>;
}

else{
    echo <p style='color:red'>$_COOKIE["answer"]</p>;
    }
[/code]

Is something like this possible?

Thanks :-)
Link to comment
https://forums.phpfreaks.com/topic/15101-reading-cookies/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.