How to save css stylesheet pointer on php session?

Tags: php,css

Problem :

I want to allow user change my website theme color by clicking on a button. Currently I save the css pointer onto the url. But when jump to other page, the css pointer is disappear from the url of new page, so the theme color back to default. How to make every pages remember the current selected css? Can I save the css pointer to php session? How to do that?

Codes :

    <link rel="stylesheet" href="css/theme-<?php if ($css=="blue" || $css == "") echo "blue"; else echo $css; ?>.css" type="text/css" media="screen" title="csstheme" /> 
    <?php require_once("session.php"); ?>       
        <a href="<?php print $_SERVER['PHP_SELF'];?>?<?php print $querystring;?>&css=blue" ><img src="" /></a>
        <a href="<?php print $_SERVER['PHP_SELF'];?>?<?php print $querystring;?>&css=green" ><img src="" /></a> 
        <a href="<?php print $_SERVER['PHP_SELF'];?>?<?php print $querystring;?>&css=pink" ><img src="" /></a>
        <a href="<?php print $_SERVER['PHP_SELF'];?>?<?php print $querystring;?>&css=white" ><img src="" /></a>
        <a href="<?php print $_SERVER['PHP_SELF'];?>?<?php print $querystring;?>&css=red" ><img src="" /></a>     

Solution :

Yes, the session would be a nice place to put it:

You could create a file that is called to set the theme-session. Pass the chosen theme to that file through the QueryString for instance. Then return the user back to the page they came from.

This is untested, but something like this:

if (isset($_GET["theme"]))
    $_SESSION["theme"] = $_GET["theme"];

header('Location: ' . $_SERVER['HTTP_REFERER']);

You could throw in a switch- or if-statement as well, to make sure that the theme session only can be set to a couple of predefined values.

Then you read the session on every page. If the theme variable is set, you use that theme, otherwise you fall back to the default theme.

Some more info for you:

    CSS Howto..

    How to create this image using CSS?

    How to hide overflow on slideshow without hiding arrows?

    How to add font to web application .css file

    How to overlay two fonts with css

    CSS: How to float 3 divs side by side for width:100% without messing up?

    How can a

    How to hide element that is currently mousedover and shown via :hover css pseudo class via jQuery

    How to make a CSS bar go from right to left?

    How to make CSS (or JS?) hideable help bar

    How to vertically center text overlapping an image?

    How can I improve this mobile site? [closed]

    How to change size to GtkWidget with CSS?

    How to get rid of column border of gridview using CSS

    How to re-size and crop an image client side while maintaining the aspect ratio

    How to select the by CSS?

    How do I modify the Datatable header style in PF Dynamic Columns?

    Show text underneath image while hovering without disrupting other elements

    How to add CSS dynamically to a controller in SAPUI5

    How to set each type of page transition to a specific page? (css animations)

    image carousel showing all images

    Best way how to put elements above an tag?

    How to make middle div acting like a fixed positioned header when middle div go to the top place by mouse scrolling

    IE11 shows every display: table-cell element at a new line

    How can I map 5 distinct zone on a draggable-vertical element?

    How to repeat a code in html without writing the same code again and again

    How to target the text in an element but not the text in nested elements with CSS

    Use CSS to show two div's with background image over a containing div

    CSS hover transition - how to remove delay?

    Show/Hide Html TR/TD

    how do you link static pages in rails to your css files? [closed]