Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 29th, 2011  |  syntax: None  |  size: 1.01 KB  |  hits: 116  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. update_styles.php
  2.  
  3. <?php
  4. $new_style = strip_tags( $_GET['style'] ); //the style the user has selected
  5. $styles = array( "blue", "red", "green" ); //the styles they can have
  6. if ( !in_array( $new_style, $styles ) ) //selected an invalid style
  7. {
  8.     echo "You can not have this style";
  9. }
  10. else //selected a valid style
  11. {
  12.     setcookie( "style", $new_style, time() + 60 * 60 * 24 * 5 ); //update "style" cookie
  13.     echo "Your style has been updated to {$new_style}!";
  14. }
  15. ?>
  16.  
  17. index.php
  18.  
  19. <?php
  20. $style = ( $_COOKIE['style'] ) ? $_COOKIE['style'] : "blue"; //if the "style" cookie has been set, read it, if not use "blue" as default style
  21. echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"css/{$style}.css\" media=\"screen\" />"; //print out the html line that will get the CSS file.
  22. ?>
  23.  
  24. Then just use something like this to switch between stylesheets.
  25.  
  26. Change theme:
  27. <a href="update_style.php?style=blue">Blue</a> |
  28. <a href="update_style.php?style=red">Red</a> |
  29. <a href="update_style.php?style=green">Green</a>
  30.