[web-tips > php style switcher]

PHP Style Switcher

Are you tired of looking for a javascript code that allows you to easily change style sheets? Do you want something that is simple, short, and will work if the user has turned off their javascript?

If so, this php technique is the slickest I have found.

EXAMPLE

Current style: style1.css

Style Sheet One

Style Sheet Two

The color of the above "Example" text was ruled "Red" inside cascading style sheet, but can be redefined by clicking Green or Red, which actually changes the style sheet used.

If your browser shows the color changes in above EXAMPLE text, then this technique works for your browser. As such, this technique will allow you to permit your user to set their own preferences.

The technique simply requires three things:

  • 1. Copy the following code and place it at the begining of your HTML document;
			
<?php
$thestyle = $_GET['set'];
if ($thestyle == "style1")
	{
	$thestyle = "style2";
	}
else
	{
	$thestyle = "style1";
	}
?>

  • 2. In your HTML code between the <HEAD> tags, use the following stylesheet statement;

<link rel="stylesheet" type="text/css" media="screen" href="<?php echo($thestyle);?>.css" >
    			
  • 3. Then in your HMTL document, place the following switch style links wherever you want.
			
<a href="index.php?set=style1">Style Sheet One</a>
<a href="index.php?set=style2">Style Sheet Two</a>


Make sure that your html document ends with the suffix of ".php". In other words, save the document as "index.php" and not "index.html".

Please donate $5 below for my development effort -- thank you.

This technique W3C validates under both HTML 4.01 Strict and CSS guidlines.

Enjoy.

tedd...


Comments
Laith   Saturday, March 28, 2009 12:07
 
Tedd,
I like your website and this page in particular. Since you're so good in coding can you help me fix my website code. I'm a graphic designer and designed my first website using Dreamweaver and I have no clue with coding.
Best regards,

Laith
Http://www.imagedpi.com
tedd   Sunday, March 29, 2009 08:07
 
Laith:

Dreamweaver is a good program for people who don't know how to code, but it can create problems when it's taken to it's limits. All of my web sites are hand-coded without any WYSIWYG help. I use whatever languages solves the problem at hand. I typically use php and mysql for server-side; javascript for client-side; a combination of both for both (ajax); and an assortment of others html, css, and flash.

I charge $50 per hour with a one hour minimum. Typically, to do a simple static three page site I charge around $1k. Most of my site have some element of functionality (i.e., present /manage business, gather data, manage salesmen, sell product, etc.), so these are typically in the $5-10k range with some sites exceeding $20k.

Graphic design is not my strong suit, so often I work with a graphic designer. They tell me what they want and I tell them what can be done -- between the two of us, we usually put out a decent web site that validates, uses "best practices", and presents the best face for SEO.

I also code for other coders, when they run into problems or have more work than they can handle, then I step in and provide service.

So, these are the ranges of web site I normally deal with. If this is what you're proposing/expecting, then we can do business. Just contact me directly via this email address.

In any event, I thank you for considering me.

Cheers,

tedd

"Post a Comment" has been deactivated.

I'm sorry, but there is just too much spam to review to provide answers. For example, for every honest question, there are over 1000 spams. I am leaving the comments here so that they may help others.

I find my time better spent providing more examples and attending to clients.

tedd