A lot of webmasters like this nice looking CSS websites with the possibility to switch between different CSS style sheets. This code snippet will help to create the switch. Just create you different style sheets and your universal coded html documents (these one have to work with all the style sheets) and at least use this code in all html documents (or with a PHP included file). Notice the links at the bottom of this site; they are created with the same function. After a visitor changed the style, his choice is stored inside a session variable.
<?php
session_start ();
$all_css = array();
$all_css [ 'yellow' ][ 'file' ] = "home_geel.css" ;
$all_css [ 'blue' ][ 'file' ] = "home_blauw.css" ;
$all_css [ 'modern' ][ 'file' ] = "home_modern.css" ; // default
$all_css [ 'yellow' ][ 'label' ] = "Yellow!" ;
$all_css [ 'blue' ][ 'label' ] = "Deep blue" ;
$all_css [ 'modern' ][ 'label' ] = "Final..." ; // default
$default_value = "modern" ; // set the default value here
if (isset( $_GET [ 'change_css' ]) && $_GET [ 'change_css' ] != "" ) {
$_SESSION [ 'css' ] = $_GET [ 'change_css' ];
} else {
$_SESSION [ 'css' ] = (!isset( $_SESSION [ 'css' ])) ? $default_value : $_SESSION [ 'css' ];
}
switch ( $_SESSION [ 'css' ]) {
case "yellow" :
$css_file = "home_geel.css" ;
break;
case "blue" :
$css_file = "home_blauw.css" ;
break;
default:
$css_file = "home_modern.css" ;
}
function style_switcher () {
global $all_css ;
$style_links = "Style switch: \n" ;
foreach ( $all_css as $key => $val ) {
if ( $_SESSION [ 'css' ] != $key ) {
$style_links .= "<a href=\"" . $_SERVER [ 'PHP_SELF' ]. "?change_css=" . $key . "\">" ;
$style_links .= "<b>" . $val [ 'label' ]. "</b></a> \n" ;
} else {
$style_links .= "<b>" . $val [ 'label' ]. "</b> \n" ;
}
}
return $style_links ;
}
?>
<!-- EXAMPLE: place this inside your html header -->
<link href="/includes/<?php echo $css_file; ?>" rel="stylesheet" type="text/css">
<!-- place this code inside the body where you want to show the links -->
<?php echo style_switcher(); ?>
XDT Topsite (Gold v1.0) Categories : Databases , CSS , PHP , HTML and PHP , Sessions Print out array key => value in colored HTML Categories : PHP , Arrays , HTML and PHP Form Submission Using Array's Categories : PHP , HTML and PHP , Beginner Guides , Arrays Parse string to find sub-string between two arbitrary strings Categories : PHP , Strings , HTML and PHP , Arrays AITSH Statistics Categories : Complete Programs , Databases , HTML and PHP , Sessions , PHP PHP4 session helper HTML file.
Categories : PHP , Java Script , HTML and PHP , Sessions Simple PHP control CSS Calendar Categories : PHP , HTML and PHP , Calendar , Date Time , CSS Parsing html tags with php. Get an array from this function Categories : PHP , HTML and PHP , Arrays , Tag Extractors Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays , Global Variables , PHP , HTML and PHP , Variables Kewl Date Example Categories : PHP , HTML and PHP , Date Time , CSS , Beginner Guides Dynamic CSS generation for multiple website colouring schemes. Categories : PHP , CSS , HTML and PHP dynamic table columns Categories : PHP , HTML and PHP , Arrays , Databases , MySQL PHP alternating the colors of table rows with style. Categories : PHP , HTML and PHP , CSS navbar.php3 - Dynamic hyperlinked navigation bars Categories : HTML and PHP , Arrays , PHP , Complete Programs Select with current month Categories : PHP , HTML and PHP , Date Time , Arrays