PHP css styles switcher


SUBMITTED BY: Guest

DATE: Oct. 23, 2013, 7:02 a.m.

FORMAT: PHP

SIZE: 1.7 kB

HITS: 1179

  1. <?php
  2. session_start();
  3. $all_css = array();
  4. $all_css['yellow']['file'] = "home_geel.css";
  5. $all_css['blue']['file'] = "home_blauw.css";
  6. $all_css['modern']['file'] = "home_modern.css"; // default
  7. $all_css['yellow']['label'] = "Yellow!";
  8. $all_css['blue']['label'] = "Deep blue";
  9. $all_css['modern']['label'] = "Final..."; // default
  10. $default_value = "modern"; // set the default value here
  11. if (isset($_GET['change_css']) && $_GET['change_css'] != "") {
  12. $_SESSION['css'] = $_GET['change_css'];
  13. } else {
  14. $_SESSION['css'] = (!isset($_SESSION['css'])) ? $default_value : $_SESSION['css'];
  15. }
  16. switch ($_SESSION['css']) {
  17. case "yellow":
  18. $css_file = "home_geel.css";
  19. break;
  20. case "blue":
  21. $css_file = "home_blauw.css";
  22. break;
  23. default:
  24. $css_file = "home_modern.css";
  25. }
  26. function style_switcher() {
  27. global $all_css;
  28. $style_links = "Style switch:&nbsp;\n";
  29. foreach ($all_css as $key => $val) {
  30. if ($_SESSION['css'] != $key) {
  31. $style_links .= "<a href=\"".$_SERVER['PHP_SELF']."?change_css=".$key."\">";
  32. $style_links .= "<b>".$val['label']."</b></a>&nbsp;&nbsp;\n";
  33. } else {
  34. $style_links .= "<b>".$val['label']."</b>&nbsp;&nbsp;\n";
  35. }
  36. }
  37. return $style_links;
  38. }
  39. ?>
  40. <!-- EXAMPLE: place this inside your html header -->
  41. <link href="/includes/<?php echo $css_file; ?>" rel="stylesheet" type="text/css">
  42. <!-- place this code inside the body where you want to show the links -->
  43. <?php echo style_switcher(); ?>

comments powered by Disqus