Discuss: Build a PHP Switcher
by Chris Clark
- Editorial Comments
83 stats on JS/Cookie usage?
So we cater for those that have JavaScript deactivated
by relaying on the user accepting cookies…
Does anybody has statistical data on this?
posted at 09:21 am on September 12, 2003 by Marek Moehling
84 A better way???
I tried to implement the code given by Peter Hawkes and all works fine after the first click… the first time visiting the page, I get:
Notice: Undefined index: csschanger in c:\hosting\webhost4life\member\braincre\sean\new\index.php on line 32
anyone know why?
posted at 08:11 pm on September 25, 2003 by Sean Martell
85 Session switcher
I am using the switcher by peter hawkes:
here is more chance that a user will have cookies disabled than JavaScript disabled. All the above will not work without cookies.
I am using SESSIONS in my version, this script assumes that PHP 4.2+ is installed and that register_globals is off with —enable-trans-sid.
Code as below:
<?php
session_start();
?>
<?php
if(isset($_GET[‘css’])){
switch ($_GET[‘css’]) {
case ‘css1’:
$stylesheet = ‘<link href=“theme1.css” type=“text/css” rel=“stylesheet”>’;
$_SESSION[‘csschanger’]=$stylesheet;
break;
case ‘css2’:
$stylesheet = ‘<link href=“theme2.css” type=“text/css” rel=“stylesheet”>’;
$_SESSION[‘csschanger’]=$stylesheet;
break;
case ‘css3’:
$stylesheet = ‘<link href=“theme3.css” type=“text/css” rel=“stylesheet”>’;
$_SESSION[‘csschanger’]=$stylesheet;
break;
case ‘css4’:
$stylesheet = ‘<link href=“theme4.css” type=“text/css” rel=“stylesheet”>’;
$_SESSION[‘csschanger’]=$stylesheet;
break;
default:
$stylesheet = ‘<link href=“cssdefault.css” type=“text/css” rel=“stylesheet”>’;
$_SESSION[‘csschanger’]=$stylesheet;
}
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html >
<head>
<title>CSS Changer</title>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1” />
<?php echo ($_SESSION[‘csschanger’])? $_SESSION[‘csschanger’]: ‘<link href=“cssdefault.css” type=“text/css” rel=“stylesheet”>’ ;?>
</head>
<body>
[url=”<?php echo $_SERVER[‘PHP_SELF’]; ?>?css=css1”]Stylesheet 1[/url]
[url=”<?php echo $_SERVER[‘PHP_SELF’]; ?>?css=css2”]Stylesheet 2[/url]
[url=”<?php echo $_SERVER[‘PHP_SELF’]; ?>?css=css3”]Stylesheet 3[/url]
[url=”<?php echo $_SERVER[‘PHP_SELF’]; ?>?css=css4”]Stylesheet 4[/url]
</body>
</html>
BUT.. Is there a way of doing it so it validates??
I have put this code as one file and used then included it each page.. can i change the style changer links to something like :
<a href=”/assets/includes/switcher.php?=masterm”
posted at 03:07 am on October 10, 2003 by Gavin
86 getting rid of Session ID
Have just found out you can hide the session ID by putting
ini_set(“session.use_trans_sid”, 1);
in your switcher code
posted at 03:21 am on October 10, 2003 by Gavin
87 getting rid of session ID
SORRY got it wrong.. U can’t change
ini_set(“session.use_trans_sid”, 1);
using runtime scripts.. U can only change it in the php.ini file, .htaccess or httpd.conf#
sorry
SEE http://www.php.net/ini_set
posted at 03:57 am on October 10, 2003 by Gavin
Discussion Closed
New comments are not being accepted, but you are welcome to explore what people said before we closed the door.
Got something to say?
Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.
Create a new account or sign in below if you’d like to leave a comment.
Subscribe to this article's comments: RSS (what’s this?)






81 Switcher doesn't work (with me)
Hi there, I’m trying to use this code to switch styles on my website. I have used ALA’s Javascript switcher before, and it worked. But I can’t get the PHP version to work! I followed the tutorial step by step, and checked everything I could. It just shows plain text without any stylesheet (even if I let it show the default one). My server runs PHP and other scripts work perfectly.
Can anyone please help me? Greetings from the Netherlands,
Nick
posted at 10:58 am on September 2, 2003 by Nick