dreamwest Posted June 6, 2009 Share Posted June 6, 2009 Im trying to set a cookie by url which works, but the ifelse script doesnt seem to detect the cookie $action= $_GET['action']; $action2 =$_GET['option']; if ($action == "cinema" ){ if ($action2 != "off" && $action2 != "on"){ $action2 = "off"; } $expire=time()+60*60*24*30; setcookie("$action", "$action2", $expire, "/" ); } if (!isset($_COOKIE['cinema'])){ $customize.= '<a href="/index.php?action=cinema&option=on">CinemaScope ON</a><br><hr>'; }elseif($_COOKIE['cinema']== "on"){ $customize.= '<a href="/index.php?action=cinema&option=off">CinemaScope OFF</a><br><hr>'; }elseif ($_COOKIE['cinema']== "off"){ $customize.= '<a href="/index.php?action=cinema&option=on">CinemaScope ON</a><br><hr>'; } echo $customize; Quote Link to comment https://forums.phpfreaks.com/topic/161224-ifelse-error/ Share on other sites More sharing options...
gevans Posted June 6, 2009 Share Posted June 6, 2009 You require a page set before a cookie is recognised by the page. Quote Link to comment https://forums.phpfreaks.com/topic/161224-ifelse-error/#findComment-850723 Share on other sites More sharing options...
dreamwest Posted June 7, 2009 Author Share Posted June 7, 2009 You require a page set before a cookie is recognised by the page. Ok im lost , ive tried doing isset but it still wont work. Can you give me an example of how it should be set out? Quote Link to comment https://forums.phpfreaks.com/topic/161224-ifelse-error/#findComment-850823 Share on other sites More sharing options...
gevans Posted June 7, 2009 Share Posted June 7, 2009 Once you set the cookie you need to refresh the page. php won't pick up a cookie set in the same script. <?php setcookie("$action", "$action2", $expire, "/" ); header("Location: ".$_SERVER['PHP_SELF']); Quote Link to comment https://forums.phpfreaks.com/topic/161224-ifelse-error/#findComment-851002 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.