jcstanley Posted May 4, 2007 Share Posted May 4, 2007 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 Quote Link to comment Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 <link rel="stylesheet" type="text/css" href="<?php echo (!$_COOKIE[style])?'default':$_COOKIE[style];?>.css" /> Quote Link to comment Share on other sites More sharing options...
jcstanley Posted May 4, 2007 Author Share Posted May 4, 2007 still not working. I don't think a cookie is being created. Quote Link to comment Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 $_GET[choice] Quote Link to comment Share on other sites More sharing options...
jcstanley Posted May 4, 2007 Author Share Posted May 4, 2007 $_GET[choice] i added that to the changestyle.php script but still no change Quote Link to comment Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 <?php $Year =31536000 + time(); setcookie ('style', $_GET[choice], $Year); header("Location: $HTTP_REFERER"); ?> Quote Link to comment Share on other sites More sharing options...
rcorlew Posted May 4, 2007 Share Posted May 4, 2007 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" ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.