PHP Random Style Switcher Tutorial
What does this do? Refresh this page...do it again. You will most likely see a different page each time you refresh. It's not really a different page. It's the same page, with a different random style applied each time.
The idea here is to present the visitor to the page with a new look everytime they visit. I admit, this is not necessarily the most practical idea, but it is fun!
The php code needed to accomplish this is actually very simple. Most of the real work is developing all the css and images for each.
<?php
// put the names of your stylesheets in an array:
$style[1] = "Blog";
$style[2] = "Business";
$style[3] = "Psychodelic";
$style[4] = "Metropolitan";
$style[5] = "Southwest";
$total = "5"; // total # of styles you are going to switch
$image_folder = "images/"; // the path to your image directory
$style_folder = "styles/"; // the path to your styles directory
$start = "1"; // assign the starting #
$random = mt_rand($start, $total); // calculate random #
// attach the path to the directory, filename,
// random number and file extension for the stylesheet:
$stylesheet = $style_folder . $style[$random] . '.css';
?>
Next in the head of your page put the following code:
<link rel="stylesheet"
type="text/css"
href="<?=$stylesheet?>" />
Now, name your stylesheets (Blog.css, Business.css, etc...) and start designing!