Forum Moderators: coopster

Message Too Old, No Replies

Basic script not working...

         

JAB Creations

11:48 pm on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This script is intended to detect if a cookie named "theme" exists. If it does, the script is to do nothing. If the cookie does not exist, it should create a cookie by the name of "theme" with a value of "classicbb". I'm not getting parsing error, actually I'm not getting anything at all either when the cookie is already set or not.


<?php
if(!isset($HTTP_COOKIE_VARS["theme"]))
{ echo return false; }

elseif (empty($HTTP_COOKIE_VARS["theme"]))
{ setcookie("theme","classicbb",time()+2592000,"/"); echo 'cookie now set';}
?>

mcavic

12:08 am on Jun 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The 'echo return false' gave me a parse error, and the isset() didn't seem to be working. Try this:

<?php

if ($HTTP_COOKIE_VARS["theme"]!= "") {
echo "already set<br>\n";
return false;
}
else {
setcookie("theme","classicbb",time()+2592000,"/");
echo "cookie now set<br>\n";
}

?>

mcibor

9:10 pm on Jun 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JAB, first of all you mixed the logic. And moreover $HTTP_COOKIE_VARS is deprecated. Use $_COOKIE instead. And you cannot echo return (Is this some kind of function that does that?)

Try this code:

error_reporting(E_ALL);
if(!$_COOKIE["theme"])
{
setcookie("theme","classicbb",time()+2592000,"/");
echo "New cookie set";
}
else echo "Cookie already there";

With this code cookie cannot be null, empty nor 0
Best regards
Michal Cibor