education81 Posted December 18, 2009 Share Posted December 18, 2009 Hi I have recently implemented a style sheet switcher to my site and is nearly complete. My Index Page Displays Simple Links To Change The Style.. Nothing Out The Ordinary# <a href="http://www.freestormtracker.com/scripts/s3.php?style=white">White<a> <a href="http://www.freestormtracker.com/scripts/s3.php?style=blue">Blue<a> Etc.. Etc.. The S3.php file is as follows. <?php // vim:et ts=4 sw=4 cindent: if (!@include('s3.cfg.php')) die("Unable to include config file!"); $set_cookie = true; if (isset($_GET['style'])) { $style = $_GET['style']; } elseif (isset($_POST['style'])) { $style = $_POST['style']; } elseif (isset($_COOKIE['style'])) { $style = $_COOKIE['style']; $set_cookie = false; } // if no style supplied, or invalid supplied... if (!isset($style) || !in_array($style, $available_styles)) { // set style to default (first available) $style = $available_styles[0]; } // our cookie will last 2 years... modify // the last argument if this isn't sufficient if ($set_cookie) setcookie('style', $style, mktime() + 2 * 356 * 24 * 60 * 60, '/', '.freestormtracker.com'); $referrer = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $default_referrer; header('Location: ' . $referrer); ?> It Calls s3.cfg.php which looks like this.. <?php // vim:et ts=4 sw=4 cindent: $style_path = 'http://www.freestormtracker.com/style/'; $available_styles = array( 'red', 'default', 'white', 'grey', 'green', 'orange', ); $default_referrer = '/'; ?> Problem is that in Chrome, Firefox etc, if i switch a colour the cookie remembers this, if i then shut the page and reopen the colour is remembered however if I change colour in I.E it will remember this only while i stay on the site, once i close the browser and reopen it it goes back to the default style??? why is this happening? Quote Link to comment https://forums.phpfreaks.com/topic/185644-php-cookie-problem-driving-me-mad/ Share on other sites More sharing options...
education81 Posted December 18, 2009 Author Share Posted December 18, 2009 Forgot to mention sorry that the following is upon every page <?php $path = substr($_SERVER['PATH_TRANSLATED'], 0, -strlen($_SERVER['SCRIPT_NAME'])); if (@include($path . '/home/freesto1/public_html/scripts/s3.cfg.php')) { $style = (isset($_COOKIE['style'])) ? $_COOKIE['style'] : $available_styles[0]; printf('<style type="text/css" media="screen">@import url(%s%s.css);</style>', $style_path, $style); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185644-php-cookie-problem-driving-me-mad/#findComment-980302 Share on other sites More sharing options...
premiso Posted December 18, 2009 Share Posted December 18, 2009 It is possible that your IE is set to only keep cookies for the browser session. Check your IE settings and make sure that it does not clear out cookies on browser close etc. As it works in FF and Chrome the problem probably lies within the IE browser settings. Quote Link to comment https://forums.phpfreaks.com/topic/185644-php-cookie-problem-driving-me-mad/#findComment-980304 Share on other sites More sharing options...
education81 Posted December 18, 2009 Author Share Posted December 18, 2009 Yeh is defo problem in I.E only which unfortunately 95% of my audience... Is there anyway to put something in the code to rectify this? Quote Link to comment https://forums.phpfreaks.com/topic/185644-php-cookie-problem-driving-me-mad/#findComment-980305 Share on other sites More sharing options...
education81 Posted December 18, 2009 Author Share Posted December 18, 2009 Whats really weird is if i open i.e with the main tab being say google, then i open another tab with my site change the style then close the tab.. if i reopen the tab the style remains changed as long as the browser its self is not closed it remains remembered.. is there a way to alter my code/cookie to get round this?? any help very much appreciated, need a quick solution to this as pressed for time.. thanks to anyone who can help. Quote Link to comment https://forums.phpfreaks.com/topic/185644-php-cookie-problem-driving-me-mad/#findComment-980308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.