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

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

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.