PHP style changer - What am I doing wrong?

Soldato
Joined
7 Mar 2005
Posts
19,610
Location
LU7
OK so last year at Uni for my final year project I redesigned a lecturer's website for him. He wanted a style changer and I managed to get a Javascript one running for him but we had issues with old versions of IE not working with it and some other issues that meant a PHP style changer would have been a better answer.

I finished the site but I'm trying to learn some PHP so I can do a website of my own. It would be nice to have a PHP style changer for the experience and also to get it working for this lecturer's site. So I went to http://www.alistapart.com/articles/phpswitch/ and using Notepad++ and WAMP have put together some stuff. Now it doesn't work yet and I was wondering if some kind PHP guru could examine my code and tell me what I'm doing wrong. I'm only a PHP beginner so I'm sure it'll be quite a simple error that I just can't see.

This is the actual PHP page I'm working with:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Marc Lister's PHP style changer test page</title>
<link rel="stylesheet" type="text/css" href="default.css" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link rel="stylesheet" type="text/css" 
	media="screen" title="User 
Defined Style" href="<?php echo 
(!$sitestyle)?'defaultstyle':$sitestyle ?>.css" />

<link rel="alternate stylesheet" 
   type="text/css" media="screen" 
   title="Classic" href="./classic.css" />
   
   <link rel="alternate stylesheet" 
   type="text/css" media="screen" 
   title="Large" href="./large.css" />
   
   <link rel="alternate stylesheet" 
   type="text/css" media="screen" 
   title="High Contrast" href="./highcontrast.css" />
   
   <link rel="alternate stylesheet" 
   type="text/css" media="screen" 
   title="Print" href="./print.css" />
   
</head>
<body>
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="./switcher.php?set=default">Default</a></li>
<li><a href="./switcher.php?set=classic">Classic</a></li>
<li><a href="./switcher.php?set=large">Large</a></li>
<li><a href="./switcher.php?set=highcontrast">High Contrast</a></li>
<li><a href="./switcher.php?set=print">Print</a></li>
</ul>
</div>
</body>
</html>

This is the switcher.php that sets the cookie:
Code:
<?php
setcookie ('sitestyle', $set, time()+31536000,
	'/', 'yourdomain.com', '0');
header("Location: $HTTP_REFERER");
?>

I have the default.css file and four other CSS files. They are all in the same folder as fym.php and switcher.php.

When I click on a link to change the style I get:
Code:
<?php
setcookie ('sitestyle', $set, time()+31536000,
	'/', 'yourdomain.com', '0');
header("Location: $HTTP_REFERER");
?>
which is just the content of the switcher. php. I realise I haven't changed the yourdomain.com to the site URL of my lecturer's or indeed my own site yet but is there another reason this isn't working and causing the style to change? If it helps the alternative styles differ in just making the font bigger or smaller or changing the background colour. Just a simple change so I can easily see if it works. As and when I get this working then I can properly specify the changes I want the alternative stylesheets to enforce. :)
 
If your seeing the content of the script printed to the screen as text then the server is not parsing the file correctly as php and is interpreting it as a text file.
 
Back
Top Bottom