PDA

View Full Version : Cookies sometime work, sometimes don't



celticpride
08-08-2011, 05:21 AM
Hello.

I'm in the process of building a theme switcher for my site and for some reason, the cookies that are being stored sometimes load and sometimes take a few page refreshes to work.

Cookie code:

<?php
//Default style
$default1 = "arial";

//Retrieve Cookie (if exists)
if( isset($_COOKIE['style-font']) ){

//Set Style
$default1 = $_COOKIE['style-font'];

}

//Retrieve Style form URL
if( isset($_GET['font']) ){

//Set Style
$default1 = $_GET['font'];

//Set cookie

header("Location: $HTTP_REFERER"); setcookie("style-font", $default1, time()*60*60*24*30);
}
?>

HTML Code:


<a href="/?font=arial">1</a>
<a href="/?font=segoe-ui">1</a>
<a href="/?font=tahoma">1</a>
<a href="/?font-droid-sans">1</a>

Other code to echo current cookie value:



<?php if ($default1 == 'arial') echo "<style type=\"text/css\">body{font-family:Arial,Helvetica,sans-serif !important}</style>"; ?>
<?php if ($default1 == 'tahoma') echo "<style type=\"text/css\">body{font-family:Tahoma,FreeSans,Verdana,sans-serif; !important}</style>";?>
<?php if ($default1 == 'segoe-ui') echo "<style type=\"text/css\">body{font-family:\"Segoe UI\",Myriad Pro,Helvetica,Arial,FreeSans,sans-serif !important}</style>"; ?>
<?php if ($default1 == 'droid-sans') echo "<style type=\"text/css\">body{font-family:'Droid Sans',sans-serif;}</style>"; ?>


If anyone has thoughts or ideas on what to improve, please let me know. Thanks!