Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    allowing viewers to change stylesheets with php

    ok, so i remember having seen a lil snippet of code somewhere in the past that allowed the viewer of the site to click a link, and it would change the stylesheet which was being used for the site. giving the site a sort of skinnable function to it. i was wondering how i would go about doing something like this. i would also like the choice to stick with the user by applying a cookie or something like that. so on return visits their choic eof skin will remain.

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well, you'd have a bunch of links e.g.

    Code:
    <a href="stylechange.php?style=s1">Style 1</a> <a href="stylechange.php?style=s2">Style 2</a> <a href="stylechange.php?style=s3">Style 3</a>
    Then, in your stylechange.php you'd have something like...

    PHP Code:
    <?php
       $style 
    $_GET['style'];
       
    setcookie('style'$styletime()+604800);
       
    header("Location: index.php");
    ?>
    Then, instead of your usual style include line, you'd have something like...

    PHP Code:
    <?php
       
    if (!isset($HTTP_COOKIE_VARS['style'])) {
          echo 
    '<link rel="stylesheet" href="defaultstyle.css" type="text/css" />';
       }
       else {
          echo 
    '<link rel="stylesheet" href="' $HTTP_COOKIE_VARS['style'] . '.css" type="text/css" />';
       }
    ?>
    So, basically, all you'd do is:

    Add the above code
    Modify the header("Location: index.php"); to go to the page you choose once the style cookie has been set
    Name all your style sheets the same as your s e.g. in stylechange.php?style=s2, the sheet would be named s2.css
    Put as many links as you need

    ~Phil~

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy it didnt work for me

    instead of directing it to the index.php, i had the code of stylechange.php on top of my page. it didn't work for me

    also want to know what does time()+604800 do?????
    Last edited by taruna; 03-07-2009 at 02:41 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •