“PHP based CSS Style Switcher” Documentation by “Web factory Ltd” v1.0


“PHP based CSS Style Switcher”

Created: 2011-01-03, revision 1
By: Web factory Ltd
Email: info@webfactoryltd.com

Thank you very much for purchasing our PHP script. If you have any questions that are beyond the scope of this help file, please feel free to email us via our user page contact form. Have a good one!


Table of Contents

  1. Quick, 5 seconds setup
  2. Advanced setup and usage
  3. Troubleshooting
  4. Requirements
  5. Sources and Credits

A) Quick, 5 seconds setup - top

Step 1 - copy switcher.php to your server

Copy the switcher.php file from the ZIP archive you downloaded into the folder on your server/computer where you keep the css files, ie /sites/mydomain/www/css/.

Step 2 - replace your CSS file reference with switcher.php

Find the line in your document's <head> section where the CSS file is defined. It should look something like this:

Replace that line with this one:

The default=my-style.css part defines the default CSS file which is loaded when the user visits the site for the first time.
Please bare in mind that the path of the CSS file is relative to switcher.php, not the HTML document.

Hit F5 to test. If nothing happens and your site looks the same as before, it's all good - the switcher is working!

Step 3 - create some links for style switching

Switching styles is easy. Just create a simple link like:

After the style is switched the user is automatically redirected back to the page he came from. If you want to change that behaviour read the advanced setup.
Please bare in mind that the path of the CSS file is relative to switcher.php, not the HTML document.


B) Advanced setup - top

All of the following parameters (PHP variables) can be found in the first couple of lines of the switcher.php file.

Default CSS file

You can define the default CSS file eather by using the GET parameter "default" ie: "switcher.php?default=my-style.css" or by setting the "$defaultStyle" PHP variable. The GET parameter overwrites the PHP one.
If you set the default CSS file in PHP there is no need to define it via the GET parameter.

Redirect URL after style change

If you leave this variable empty (as is by default) the user will be redirect back to the page he clicked change-style link on. If you set this variable he'll always be redirect to that URL. URL can be apsolute or relative in reference to switcher.php.

Style variable expiration time

You can configure the amount of time the script remembers the users style choice (it's saved in a cookie). By default it remembers it during the corse of one session.
Available predefenied times are: session, hour, day, week, month, year. Or you can enter the number of seconds.

Gzip CSS file on output

If you want the script to gzip the CSS file on output set the "$gzipOutput" variable to "true". The CSS file itself remains unaltered. Gziping is done in realtime.
Default setting for gziping is true.

Using multiple switchable CSS files on the same page

The script supports switching multiple CSS files on the same page by creating multiple instances of the script. Lets assume you want to include 3 CSS files on your page.

Step 1 - Create 2 copies of switcher.php and give them unique names ie: switcher2.php and switcher3.php. Place all 3 PHP files in you CSS folder just as you would do with a single instance of the script.

Step 2 - Include your new CSS switchers into HTML.

You can use the GET "default" parameter or configure "$defaultStyle" variable in each file.

Step 3: create the switching link:

Don't forget to set "style=multiple" parameter, it's mandatory. For every switcher instance (switcher.php, switcher2.php, switcher3.php) you have to create a new GET parameter "switcher-filename.php=CSS-filename.css". Again, please note all CSS paths are relative to the PHP files.


C) Troubleshooting - top

Here are some quick pointers and reminders:


D) Requirements - top

The script requires a web server (Unix/Linux, Windows or any other OS) running PHP 4.3 or later. No other modules or components are needed.
PHP has to have "normal" read access to files in your public www folder. That's normal on 99% servers. If yours differs please contact your server administrator or us.
Needless to say this is a server-side script so it's 101% compatibile with all browsers.


E) Sources and Credits - top

No external assets or copyrighted materials were used in this script.


Once again, thank you so much for purchasing this PHP script. As stated at the beginning, we'd be glad to help you if you have any questions relating to this theme. We'll do our best to assist. If you have a more general question relating to the themes on CodeCanyon, you might consider visiting the forums and asking your question in the "Item Discussion" section.

Web factory Ltd.

Go To Table of Contents