AXiSS Posted January 15, 2007 Share Posted January 15, 2007 I am working on a site and trying to make templates, which users can switch between. I thought a cookie would be the best way to remember the user's choice. At the beginning of the index page I have[code]<?phpif(!isset($_COOKIE['template'])) {setcookie('template', '2_3.css');}[/code]But that isn't setting a cookie for some reason. If I click on a different template link which goes to a page with just a setcookie function that redirects back to the homepage, the cookie is set.Secondly, if I exit the browser and come back, it doesn't read the cookie, so is there anything I need to include to make the cookie permanent? Quote Link to comment Share on other sites More sharing options...
AXiSS Posted January 16, 2007 Author Share Posted January 16, 2007 If you want to see for yourself go to http://penguinisland.net/2.3/index.php Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted January 16, 2007 Share Posted January 16, 2007 The cookie only becomes active after the next page load. If you load your page without any cookies, then refresh, it'll work fine. To get around it, have just this code on index.php, and change your current index.php to main.php (or something else you like).[code]<?phpif(!isset($_COOKIE['template'])) {setcookie('template', '2_3.css');}header("Location:main.php");?>[/code] Quote Link to comment Share on other sites More sharing options...
AXiSS Posted January 16, 2007 Author Share Posted January 16, 2007 [quote author=Cagecrawler link=topic=122552.msg505776#msg505776 date=1168917697]The cookie only becomes active after the next page load. If you load your page without any cookies, then refresh, it'll work fine. To get around it, have just this code on index.php, and change your current index.php to main.php (or something else you like).[code]<?phpif(!isset($_COOKIE['template'])) {setcookie('template', '2_3.css');}header("Location:main.php");?>[/code][/quote]OK, I'll try that out. Thanks for the help! 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.