• Link us
  • Links
  • TOS
  • Site
  • Gallery
  • Forum
Subscribe

Random Style - PHP & MySQL tutorial

Tutorials > PHP & MySQL tutorials > Random Style
  • Added: Aug 17th, 2006
  • Level: Easy
  • Author: hp
  • Reads: 14,278
  • Description: Learn a quick way to use a random CSS for your layouts.
Bookmark Digg del.icio.us

E-mail to a friend

View printable version


This is a very simple tutorial which requires almost no PHP knowledge. Few days back, I made a code for random quotes. Then I figured out that instead of random Quotes why don’t use random Styles? It’s just easy as saying cool.

Proceeding with the tutorial. In this tutorial, you will need two or more CSS files. For example, I have two CSS files and I need to change the style of my web site randomly. Let’s name the first file as greenstyle.css and bluestyle.css.

Now, create a new txt file and add this code to it:

<link rel="stylesheet" type="text/css" href="greenstyle.css">
--NEXT--
<link rel="stylesheet" type="text/css" href="bluestyle.css">

Now the explanation:
The first line of the code generates a style named greenstyle.css. The second line is just a command I used for separating the codes. And finally, the third line, in the line, I have given him the code of bluestyle.css so that it can generate a style in between the two styles.

Now save the txt file as randomlayout.txt and upload it to the directory of header.php file or whatever you named it.

PHP time now. You have to do nothing just add the following code to the header of each page or to the header.php file:

<?php srand((double)microtime()*1000000);
$arry_txt=preg_split("/--NEXT--/",join('',file("randomlayout.txt")));
echo 
$arry_txt[rand(0,sizeof($arry_txt)-1)]; ?>

Just put the code in header.php file and then you are done.
Don’t know what’s header.php? check out the php includes tutorial for more information.

Please remember to replace you current .CSS code with the PHP code. Or, the tutorial may not function.

Have a good day.


If you like this tutorial why not digg it or add to del.icio.us?

Tutorial © hp. Do not reproduce in any way without previous permission from the author.

  • Members login
  • Register for free

Web layouts

  • Web layouts
  • Aardvark Topsites skins
  • SMF Themes
  • Wordpress Themes

Graphic resources

  • 100x100 Avatars
  • PS and PSP brushes
  • Brush shop
  • Background patterns
  • Web icons and smilies
  • Textures
  • Renders (PNG)

Tutorials

  • Newest tutorials
  • Adobe Photoshop
  • CSS
  • Designs / Layouts
  • HTML & XHTML
  • Miscellaneous
  • Paint Shop Pro
  • PHP & MySQL

Affiliates

  • Ego Box
  • The Jaded Network

Partners

Celestial Star © Melfina 2003-2010. By using this site you agree to our terms of service
Layout credits: Hybrid Genesis, Bittbox, swe3ty
Valid XHTML | Valid CSS | Top of the page