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 : CSS style switcher
Categories : PHP, CSS, HTML and PHP, Arrays, Sessions Click here to Update Your Picture
Olaf Lederer
Date : Jul 12th 2005
Grade : 3 of 5 (graded 4 times)
Viewed : 6154
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Olaf Lederer
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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
Dynamic CSS generation for multiple website colouring schemes.
Categories : PHP, CSS, HTML and PHP
PHP alternating the colors of table rows with style.
Categories : PHP, HTML and PHP, CSS
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
How to pass an array from one PHP Script to another via an HTML form
Categories : PHP, HTML and PHP, Arrays
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
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
AITSH Statistics
Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP
Parsing html tags with php. Get an array from this function
Categories : PHP, HTML and PHP, Arrays, Tag Extractors
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Form Security - Match A Value For Success
Categories : PHP, Authentication, HTML and PHP, Sessions, Security
Simple PHP control CSS Calender
Categories : PHP, HTML and PHP, Calendar, Date Time, CSS
navbar.php3 - Dynamic hyperlinked navigation bars
Categories : HTML and PHP, Arrays, PHP, Complete Programs
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