multiple stylesheets using cookies


SUBMITTED BY: phpsnippets

DATE: Oct. 21, 2015, 2:07 p.m.

FORMAT: Text only

SIZE: 1.1 kB

HITS: 1671

  1. <?php
  2. function styleSheet($currentCookie){
  3. # Get Current Style Sheet
  4. $currentCookie = $_COOKIE["StyleSheet"];
  5. # Get New cookie file name
  6. switch($_GET['style']){
  7. case 1:
  8. $value = 'style1.css';
  9. break;
  10. case 2:
  11. $value = 'style2.css';
  12. break;
  13. case 3:
  14. $value = 'style3.css';
  15. break;
  16. default:
  17. $value = 'style.css';
  18. break;
  19. }
  20. # If the user views this page, without using
  21. # style=... then set cookie to the default
  22. if(!isset($_GET['style'])){
  23. $value = 'style.css';
  24. }
  25. # If the new value doesn't equal the old value allow cookie change
  26. if(isset($value)||$currentCookie!=$value||isset($currentCookie)){
  27. setcookie("StyleSheet", $value, time()+600000); /* expires in 10,000 hours*/
  28. return $_COOKIE["StyleSheet"];
  29. }else{
  30. return $_COOKIE["StyleSheet"];
  31. }
  32. if(isset($_GET['style'])){
  33. header("Location: ".$_SERVER['HTTP_REFERER']);
  34. exit;
  35. }
  36. }
  37. ?>

comments powered by Disqus