phpQuestioner Posted November 9, 2007 Share Posted November 9, 2007 I am trying to create a user interaction experience on a web page that lets them choose there layout, but I do not want it to be just CSS based; I want it be PHP based. I am having trouble setting and erasing my cookies to make this work. I pretty sure the reason is because the code that checks for the cookie is in the top of the page and it is stopping the execution of the other if else condition. The thing is, that I am not sure exactly were to put this code at to make it work like I want it to. I tried to nest the if else condition, that checks for the cookie in the if else condition that checks for the layout, but that did not help. Can someone give my code below a once over and tell me what would be the best we to go about doing this. <?php if (isset($_COOKIE['expanded'])) { setcookie("normal","",time()-3600); $layout="v2"; } else if (isset($_COOKIE['normal'])) { setcookie("expanded","",time()-3600); $layout="v1"; } else { setcookie("expanded","",time()-3600); setcookie("normal","",time()-3600); $layout=""; } if ($layout == "v2") { setcookie("expanded","layout",time()+3600); // display expanded layout here } else if ($layout == "v1") { setcookie("normal","layout",time()+3600); // display normal layout here } else { // display normal layout here } ?> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 9, 2007 Author Share Posted November 9, 2007 Anybody? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 9, 2007 Author Share Posted November 9, 2007 OK - I figured out how to do this. I decided to only check for the expanded version cookie, but I set a normal version cookie, just as a back up (probably really did not need that - I know). This did accomplish what I wanted it to do though; so maybe this will help some else out who is trying to create a php version of a user defined layout switcher - any way, I hope it does. <?php // User Designated Page Layout Cookie Will Return To Their Specifically Chosen Layout For 90 Days if ($layout == "v1") { setcookie("expanded","",time()-7776000); } else if (isset($_COOKIE['expanded'])) { $layout="v2"; } ?> <head> <title>Untitled</title> </head> <body> <?php if ($layout == "v1") { setcookie("normal","layout",time()+7776000); // display layout version 1 contents } else if ($layout == "v2") { setcookie("normal","layout",time()-7776000); setcookie("expanded","layout",time()+7776000); // display layout version 2 contents } else { // display layout version 1 contents } ?> </body> </html> 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.