1. Home
  2. Computing & Technology
  3. PHP / MySQL

PHP CSS Switcher

By Angela Bradley, About.com

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.
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. CSS Switcher PHP - PHP Style Switcher - PHP Change CSS

©2009 About.com, a part of The New York Times Company.

All rights reserved.