Advertisement
Guest User

Untitled

a guest
Nov 29th, 2011
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement