CSS Changer

Discussion in 'PHP' started by webber09, Mar 19, 2010.

  1. #1
    Hi everyone,

    I was wondering if there is a script around that will change which CSS file the web page reads from depending on which is selected by the user. I have seen it before and am unsure if it will be PHP or JS.

    Thanks in advanced, much appreciated.
     
    webber09, Mar 19, 2010 IP
  2. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    you can use php or js, it's depend on you.
     
    guardian999, Mar 19, 2010 IP
  3. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #3
    which one would be better for seo ect.?
     
    webber09, Mar 19, 2010 IP
  4. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #4
    I think you are a bit confused... Anyway in PHP you can create a simple function that will change the style of the PAGE whenever you will need it or you can create a simple script that will store a CSS file for every page, or you can create a script that will change it randomly or you can create a script that will read from a database which style to load for a specified content or you can do a simple PHP script that will allow users (if we are talking about a website that allow registration) that will allow users to decide the template...

    But if you will clarify a bit your question we will be able to help you more :)
     
    YoGem, Mar 21, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    This should get you started, save it for example as style.php:

    <?php
    /* basic php example */
    if($_GET['style'] == 'green'){
    //green stylesheet...
    echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"".$_GET['style']".css\">";
    } else if($_GET['style'] == 'blue'){
    //blue stylesheet...
    echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"".$_GET['style']".css\">";
    } else {
    //the default stylesheet, if none is selected.
    echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"default.css\">";
    }
    ?>
    PHP:
    Then the user can select their style such as: style.php?style=green, and it would embed the green.css stylesheet...

    You can further enhance the code, using sessions etc.
     
    danx10, Mar 21, 2010 IP
  6. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #6
    thanks very much all, have use the script Danx10 gave... works a treat. thanks again :D
     
    webber09, Oct 10, 2010 IP