Jump to content

Stylesheet switcher not working


jcstanley

Recommended Posts

Hi

 

I am new to the whole idea of stylesheets so thought I would give them a try.

 

What I am trying to do is provide different colour schemes (only 2 at the moment, blue - default.css and orange - orange.css) which the user can select.

 

I have read numerous tutorials but can't get any of them working.  The one used below is from about.com:

 

The head section of the index.htm page is as follows:

 

<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="<?php echo (!$style)?'default':$style ?>.css" /> 

</head>

 

The links for the different styles are as follows:

 

<a href="changestyle.php?choice=orange"> Orange</a> | <a href="changestyle.php?choice=Blue"> Blue</a>

 

and the changestyle.php script:

<?php 
$Year =31536000 + time();
setcookie ('style', $choice, $year);
header("Location: $HTTP_REFERER"); 
?>

 

All seems quite straight forward but when the index.htm page is views the default.css (blue) style has not been applied.  When you click on a link to change it to Orange for example, the page reloads but there is no change in appearance.

 

Any ideas what could be wrong?

 

Many thanks

 

 

 

 

Link to comment
Share on other sites

Ok try changing this:

 

<?php echo (!$style)?'default':$style ?>

 

To this:

if($_COOKIE[style] == null) {$style="blue";}

if($_COOKIE[style] != null) {$style="$_COOKIE[style]";}

 

<?php echo "$style" ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.