cheesycarrion Posted January 21, 2007 Share Posted January 21, 2007 I'm trying to make a form with a checkbox for setting if you want to see the welcome page when you go to my site. I have three pages:settings form - /directory.php?page=settings - [url=http://carrion.9999mb.com/directory.php?page=settings]http://carrion.9999mb.com/directory.php?page=settings[/url][code]<div class="newsarticle"><div class="newsarticletitle">Settings</div><div class="newsarticlebody"><p><b><img src="images/icons/notice.png" />These are saved as cookies on your computer. You must have cookies enabled for these settings to work right. They won't stay attached to your account on CC.</b></p><form action="directory.php" method="GET"><input type="hidden" name="page" value="settings" /><input type="hidden" name="location" value="2" /><!-- I put these hidden forms here because the results page isn't right on directory.php; I have lots of other pages in it too. --><!-- I didn't know how to say "if the checkbox is checked" in the results page so I used a textbox. Please help me with this too. :) --><p><input type="text" name="homeswitch" value="<?phpif ($_COOKIE['homeswitch']=='1'){echo '1';}elseif ($_COOKIE['homeswitch']=='0'){echo '0';}else{echo '1';// by default the homepage is on.}?>" /> Display Welcome Page - Type 1 or 0</p><p><input type="submit" value="done" /><input type="reset" value="cancel" /></p></form></div></div>[/code]results form - /directory.php?page=settings&location=2 - [url=http://carrion.9999mb.com/directory.php?page=settings&location=2]http://carrion.9999mb.com/directory.php?page=settings&location=2[/url][code]<?phpif ($homeswitch >= "1"){setcookie("homeswitch", "1", time()+1000000000);// this one says that it's enabled and to keep the cookie for one billion seconds, I think. }elseif ($homeswitch == "0"){setcookie("homeswitch", "0", time()-3500);// this should be to delete the cookie}?>[/code]results form - /index.php - [url=http://carrion.9999mb.com/]http://carrion.9999mb.com/[/url][code]<?phpif ($_COOKIE['homeswitch']=="1"){header ("location: directory.php");}else{ // the index page is displayed here.}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/ Share on other sites More sharing options...
trochia Posted January 21, 2007 Share Posted January 21, 2007 Sets cookie for 120 days$cookieTime = time() + 60*60*24*120; Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165490 Share on other sites More sharing options...
cheesycarrion Posted January 21, 2007 Author Share Posted January 21, 2007 thanks. one billion seconds wasn't really ideal. I'm still having the problem though. I still know I messed on something else in there. Also there's still the checkbox issue. Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165491 Share on other sites More sharing options...
trochia Posted January 21, 2007 Share Posted January 21, 2007 Just create a button to : http://www.php.net/manual/en/function.session-destroy.phpIsn't that the goal? Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165493 Share on other sites More sharing options...
cheesycarrion Posted January 21, 2007 Author Share Posted January 21, 2007 well the problem I'm having is creating the cookie. All the cookie is supposed to do is to disable the homepage and have it redirect to directory.php. I'll keep that in mind for getting rid of the cookie though. Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165501 Share on other sites More sharing options...
trochia Posted January 21, 2007 Share Posted January 21, 2007 Are you storing a session for it? Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165503 Share on other sites More sharing options...
cheesycarrion Posted January 21, 2007 Author Share Posted January 21, 2007 no. does it only need to be in the index? Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165507 Share on other sites More sharing options...
trochia Posted January 21, 2007 Share Posted January 21, 2007 You'll want to set it, during your inital login-registration... and you'll be checking for it from your index, (if you want) or on links after one views intial site for the first time.session_start; session_register("s_email");----------http://us3.php.net/manual/en/features.http-auth.php Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165516 Share on other sites More sharing options...
cheesycarrion Posted January 21, 2007 Author Share Posted January 21, 2007 Thanks trochia. Now it's working perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165907 Share on other sites More sharing options...
trochia Posted January 21, 2007 Share Posted January 21, 2007 Not a problem...glad I could help..... Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165908 Share on other sites More sharing options...
cheesycarrion Posted January 22, 2007 Author Share Posted January 22, 2007 here's what it is now:settings page (with unimportant parts cut out):[code]<p><input type="checkbox" name="homeswitch" value="homeon" <?phpif ($_COOKIE['homecookie']=='1'){echo 'checked';}elseif ($_COOKIE['homecookie']=='0'){echo '';}else{echo 'checked';}?> /> Display Welcome Page</p>[/code]I cut a lot of other stuff from the page out because I made a stylesheet switcher script in the same form.That submits to this page (GET), again cutting out the bit for the style changer:[code]<?php$cookieTime = time() + 60*60*24*120;$homeswitch = $_GET["homeswitch"];session_start; session_register("homepageon");if ($homeswitch==null){setcookie("homecookie", "0", $cookieTime);}elseif ($homeswitch=="homeon"){setcookie("homecookie", "1", $cookieTime);}?>[/code]and on the index page[code]<?phpif ($_COOKIE['homecookie']=="0"){header ("location: directory.php");}else{// the 'click to enter' page is here}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-166118 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.