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. Link to comment https://forums.phpfreaks.com/topic/45710-cookie-problem-code-worked-on-one-server-but-not-on-another/ 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 Link to comment https://forums.phpfreaks.com/topic/45710-cookie-problem-code-worked-on-one-server-but-not-on-another/#findComment-222042 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. Link to comment https://forums.phpfreaks.com/topic/45710-cookie-problem-code-worked-on-one-server-but-not-on-another/#findComment-222047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.