Code Snippet </> Info
Snippet Name: CSS Stylesheet Switcher
Description: CSS Stylesheet Switcher allows your visitors to select the style they like your website to appear.
Note:
Author: SnapBuilder
Last Modified: 2019-12-10 01:31:34
Language: php
Highlight Mode: phphtml
|
Copy Codes: Use Free Notepad ++ |
|
Snap HTML Code Editor: Paste the source code, make changes and instantly see it in live preview. Snap HTML Code Editor
|
|
Copied To Clipboard!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>CSS Stylesheet Switcher</title>
<!-- EXAMPLE: place this inside your html header -->
<link href="/includes/<?php echo $css_file; ?>" rel="stylesheet" type="text/css">
</head>
<body>
<?php
// Begin CSS Stylesheet Switcher
// == This Script Free To Use Providing This Notice Remains == //
// == This Script Has Been Found In The https://snapbuilder.com Free Public Codes Library == //
// == NOTICE: Though This Material May Have Been In A Public Depository, Certain Author Copyright Restrictions May Apply == //
session_start();
$all_css = array();
$all_css['yellow']['file'] = "home_yellow.css";
$all_css['blue']['file'] = "home_blue.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 your CSS default value name 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_yellow.css";
break;
case "blue":
$css_file = "home_blue.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;
}
?>
<!-- place this code inside the body where you want to show the CSS Style links -->
<?php echo style_switcher(); ?>
</body>
</html>
|