Jump to content

PHP Cookie Problem???? Driving Me Mad.


education81

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/185644-php-cookie-problem-driving-me-mad/
Share on other sites

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

?>

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.

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.

Archived

This topic is now archived and is closed to further replies.

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