Jump to content


Photo

Reading cookies


  • Please log in to reply
3 replies to this topic

#1 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 20 July 2006 - 04:06 AM

Hi,

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

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"];

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

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>;
     }

Is something like this possible?

Thanks :-)

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 July 2006 - 04:15 AM

try this ok for an idear ok.


<?

$name="redarrow";

$result=str_replace("r","<font color='red'>r</font>",$name);



echo $result;

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 20 July 2006 - 04:22 AM

Yep, that will do the trick! Thanks a lot :-)

Neil

#4 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 20 July 2006 - 04:46 AM

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


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

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


Thanks :-)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users