Advertisement
RJDDevelopment

CSS & JS Through PHP

Apr 24th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2. $_GET['cache'] = isset($_GET['cache']) && ctype_alpha($_GET['cache']) ? trim($_GET['cache']) : 'cache';
  3.  
  4. switch ($_GET['cache']) {
  5.     case 'styles' : init_css();
  6.         break;
  7.     case 'scripts': init_js();
  8.         break;
  9.     default :
  10.         echo "Script requires an action.";
  11. }
  12.  
  13. function init_css() {
  14.     header("Content-type: text/css");
  15.     $bgcolor = "#000";
  16.     ?>
  17.     body
  18.     {
  19.         background-color: <?php echo $bgcolor; ?>
  20.    
  21.     }
  22. <?
  23. }
  24. ?>
  25. <?php
  26. function init_js() {
  27.     header("Content-type: text/javascript");
  28. ?>
  29.   alert('Javascript through php file.');
  30. <? }
  31. ?>
  32.  
  33. <link rel="stylesheet" href="cache.php?cache=styles" type="text/css" />
  34. <script src="cache.php?cache=scripts" type="text/javascript"></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement