1. Computing

PHP CSS Switcher

By , About.com Guide

1 of 3

CSS On Your Pages
Having different CSS allows you to create different appearances for the same website. Using PHP you can let your users choose their preferred style, by offering multiple style options and setting a cookie to store the user's preference.
<link rel="stylesheet" type="text/css" href="<?php echo (!$style)?'normal':$style ?>.css" /> 
This code is placed on all your pages to point to the appropriate stylesheet. Unlike a normal stylesheets, we are using <?php echo (!$style)?'mainstyles':$style ?> instead of the stylesheet name. What this code says is: if no style is set in the cookies, use normal.css, but if a style is set, use stylename.css. The style name is stored as $style.
Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Step By Steps
  5. CSS Switcher PHP - PHP Style Switcher - PHP Change CSS

©2013 About.com. All rights reserved.