magicmoose Posted April 5, 2007 Share Posted April 5, 2007 Hi, I have a piece of code which I want to use to allow the user to select a stylesheet. I had it working fine on another site, but I have just added the same code to a new site I am making and it's not working. At the top of my page I have: <? if (isset($_COOKIE["selectedStyle"])) // has the cookie already been set { $style=$_COOKIE["selectedStyle"]; }else{ $style = 0; } if (isset($_POST["changeStyle"])) // changing the style { $style=$_POST["changeStyle"]; } setcookie("selectedStyle",$style); // update or create the cookie ?> In the head tags I have this: <LINK REL="stylesheet" HREF="stylesheet<?= $style; ?>.css"> And in the body of the page I have the following form: <form method="post" action="<?= $_SERVER["PHP_SELF"];?>"> <P class="general">Normal<input type="radio" name="changeStyle" value="0" checked><BR></P> <P class="general">Text Only (No Flash Content)<input type="radio" name="changeStyle" value="1"><BR></P> <INPUT type="submit" name="submitstyle" value="Change"><BR> </form> Can anyone see any problems with it? If not, what settings do I need to get changed? I can post the settings from the php.php files if needed. Thanks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 <?= requires short tags to be on. Better practice would be <?php echo Quote Link to comment Share on other sites More sharing options...
magicmoose Posted April 5, 2007 Author Share Posted April 5, 2007 Didn't know that, thanks. I forgot to mention, after the form is submitted, the stylesheet DOES change, but only for one page. It goes back to the default value afterwards, whether I load up a different page, or the same one again. I am having a similar problem with sessions, it just seems that nothing will pass from one page to another. I have tried just putting a random value in both a cookie and session variable and echoing it on another page, but nothing is displayed. 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.