WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Dynamic CSS generation for multiple website colouring schemes.
Categories : PHP, CSS, HTML and PHP Click here to Update Your Picture
Ioannis Cherouvim
Date : Apr 16th 2005
Grade : 4 of 5 (graded 5 times)
Viewed : 8273
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ioannis Cherouvim
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

You can view a working example at : http://www.weberdev.com/examples/4133_index.php?color=255

<?php

//***************************************************************
//** title  : Dynamic CSS generation for multiple website colouring schemes.
//**
//** file   : style.php
//**
//** story  : Ever wanted to provide your user with buttons where from
//**          he could change the colour scheme of the page ? Or even
//**          provide deferent colour scheme each day, randomly or
//**          depending on your mood (??). This script will show you
//**          the basic idea of how to provide a php script which
//**          will generate CSS on the fly.
//**         
//**          The idea is that given a single 24bit number representing
//**          3 8bit colour values (RGB) we can generate 10 shades based
//**          on that desired colour. Then by using those 10 shades
//**          we ensure that the site will have a uniform feel.
//**         
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date   : 2005-03-22
//***************************************************************

    //the 24bit value representing the desired colour
   
$get_color = (isset($_GET["color"]) ? $_GET["color"] : "");

   
//some basic algorithm to extract the the RGB values
   
$r = ($get_color % 256)/2;
   
$g = (($get_color >> 8) % 256)/2;
   
$b = ((($get_color >> 8) >> 8) % 256)/2;

   
//make gradients
   
$c = appendGrads(doGrad($r), doGrad($g), doGrad($b));

   
//simple algorithm to convert a 16bit dec to hex
   
function dec2hex16bit($dec) {
       
$digits = "0123456789ABCDEF";
        return (
$dec>-1 && $dec<256?$digits[$dec / 16].$digits[$dec % 16]:"XX");
    }

   
//produces 10 shades of a 8bit value
   
function doGrad($c) {
        for (
$i = 0; $i < 10; $i++) $grad[$i] = dec2hex16bit(floor($c + ($i*(255-$c)/12)));
        return
$grad;
    }

   
//concatenates the 8bit RGB hex values into a 24bit one
   
function appendGrads($r, $g, $b) {
        for (
$i = 0; $i < 10; $i++) $grad[$i] = $r[$i].$g[$i].$b[$i];
        return
$grad;
    }

?>
body {
    background-color: #<?php echo $c[9]?>;
    margin: 50px 50px 50px 50px;
}

.table1 {
    border: solid 2px #<?php echo $c[2]?>;
    background-color: #<?php echo $c[6]?>;
    width: 100%;
    height: 100%;
    text-align: center;
}
.table1 th {
    font-family: Verdana, Sans-Serif;
    font-size: 18px;
    letter-spacing: 3px;
    color: #<?php echo $c[0]?>;
    border: solid 2px #<?php echo $c[4]?>;
    background-color: #<?php echo $c[8]?>;
    height: 50px;
}
.table1 td {
    border: solid 2px #<?php echo $c[4]?>;
    background-color: #<?php echo $c[7]?>;
    text-align: center;
    width: 100%;
}

a:link, a:visited, a:active {
    font-family: Arial, Sans-Serif;
    font-size: 16px;
    background-color: #<?php echo $c[6]?>;
    color: #<?php echo $c[0]?>;
    border: solid 2px #<?php echo $c[4]?>;
    text-decoration: none;
    font-weight: bold;
    margin: 10px 10px 10px 10px;
    padding: 10px 10px 10px 10px;
}

a:hover {
    border: solid 2px #<?php echo $c[6]?>;
    background-color: #<?php echo $c[9]?>;
}




<?php

//***************************************************************
//** title  : Dynamic CSS generation for multiple website colouring schemes.
//**
//** file   : index.php. an example use of the style.php above
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date   : 2005-03-22
//***************************************************************

   
$self = $_SERVER['PHP_SELF'];

    echo
"<html><head><style type='text/css'>";
    include
"style.php";
    echo
"</style><title>Dynamic CSS</title></head>";

    echo
"<body>";
    echo
"<table class='table1'>";
    echo
"<tr><th colspan='2'>Dynamic CSS - Click on buttons to change colors</th></tr>";
    echo
"<tr><td>";

    echo
"<a href='$self?color=255'>Red</a>";
    echo
"<a href='$self?color=13566115'>Purple</a>";
    echo
"<a href='$self?color=1032208'>Green</a>";
    echo
"<a href='$self?color=16711680'>Blue</a>";
    echo
"<a href='$self?color=65536'>Gray</a>";
    echo
"<a href='$self?color=10181680'>Navy</a>";
    echo
"<a href='$self?color=".mt_rand(0, 16777216)."'>Random</a>";

    echo
"</td></tr></table>";
    echo
"</body></html>";
?>



XDT Topsite (Gold v1.0)
Categories : Databases, CSS, PHP, HTML and PHP, Sessions
PHP alternating the colors of table rows with style.
Categories : PHP, HTML and PHP, CSS
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Simple PHP control CSS Calender
Categories : PHP, HTML and PHP, Calendar, Date Time, CSS
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
CSS style switcher
Categories : PHP, CSS, HTML and PHP, Arrays, Sessions
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
Constantly refresh your PHP/HTML page data.
Categories : PHP, HTML and PHP, Sybase
Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories : Algorithms, HTML and PHP, PHP, Variables
background music script for random notes in a frame
Categories : PHP, Content Management, HTML and PHP
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP