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
Share on other sites

This is the end result, which works prefectly :-)

[code]

$response=$_COOKIE["answer"];
$answ = explode(" ", $response);
if ($answ[0] == 'Sorry')
{
echo "<font color='red'>$response</font>";
}

else {
echo "<font color='green'>$response</font>";
}

[/code]

Thanks :-)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.