bluefusionxl Posted July 29, 2007 Share Posted July 29, 2007 Okay so my PHP cookies are created fine. But then on a different page where I try to delete them, it's a different story. It seems it creates a new cookie and deletes the new instance, from what I've experimented by setting the time forward instead of in the past. The original cookies are untouched. Firefox and IE has trouble with this. Opera does not. Cookie Creation <?php if ($_SESSION['level']=="") { if (isset($_POST['rm_user'])) { $signin = new signin(); $status = $signin->execute($_POST['rm_user'],$_POST['rm_pass']); if($status==1) { //Setting user sessions mysql_connect($db_host,$db_user,$db_pass) or die($error_db_connect); mysql_select_db($db_name) or die($error_db_select); $signin_query = mysql_query("SELECT * FROM users WHERE username='{$_POST['rm_user']}' LIMIT 1") or die($error_db_select); $_SESSION['level'] = mysql_result($signin_query,0,"level"); $_SESSION['username'] = mysql_result($signin_query,0,"username"); mysql_close(); //Setting remember me cookie if ($_POST['rm_remember']=="Remember") { $rm_pass = md5($_POST['rm_pass']); setcookie("remember1",$_POST['rm_user'],time()+60*60*24*14,"/",$domain,0); setcookie("remember2",$rm_pass,time()+60*60*24*14,"/",$domain,0); } echo(" <script type='text/javascript' language='javascript'> <!-- document.location='{$http_url}'; //--> </script> "); } else { define("tpl_page",$page_user_login); $init_page = new template(); $init_page->display("header"); $init_page->display("user_login_error"); //$init_page->ad("leader"); $init_page->display("footer"); } } else { define("tpl_page",$page_user_login); $init_page = new template(); $init_page->display("header"); $init_page->display("user_login"); //$init_page->ad("leader"); $init_page->display("footer"); echo($_SESSION['level']); } } else { echo("<script type='text/javascript' language='javascript'> <!-- var answer = confirm('{$error_signedin}'); if (answer){ window.location = '{$http_url}/sign-out'; } else{ history.back(); } //--> </script>"); } ?> Cookie Deletion <?php /*------------------------------------------------------------- # -user.php- # # Created by BlueFusionX Networks for Scoped.tv # # Created on Mon July 09 2007 12:18 AM # # Revised on Mon July 09 2007 12:18 AM # --------------------------------------------------------------*/ //Here we start user sessions session_start(); //Here we are auto-loading the classes for specific functions function __autoload($al_class) { require_once ("inc/classes/{$al_class}.php"); } //Here we load global files needed for the script require("inc/global.php"); //Here we produce the login page if ($act=="signin") { require("signin.php"); } elseif ($act=="signout") { unset($_SESSION); session_destroy(); setcookie("remember1","",time()-3600,"/",$domain,0); setcookie("remember2","",time()-3600,"/",$domain,0); echo("<script type='text/javascript' language='javascript'> alert('{$message_signedout}'); document.location='{$http_url}/sign-in'; //--> </script>"); } ?> Quote Link to comment Share on other sites More sharing options...
ChadNomad Posted July 29, 2007 Share Posted July 29, 2007 Wouldn't it be: setcookie("remember1","", time()-60*60*24*14,"/",$domain,0); setcookie("remember2","",time()-60*60*24*14,"/",$domain,0); It looks like your doing (60*60*24*14 - 3600) which won't expire the cookie. That's not long enough right? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 29, 2007 Share Posted July 29, 2007 If you need to delete a cookie, then just set it's expiry time to something in the past. E.g. time()-3600 (an hour ago). Quote Link to comment Share on other sites More sharing options...
bluefusionxl Posted July 29, 2007 Author Share Posted July 29, 2007 Signin.php creates the cookie while user.php tries to delete it. If you look at user.php, it is setting time in the past. Quote Link to comment Share on other sites More sharing options...
bluefusionxl Posted July 29, 2007 Author Share Posted July 29, 2007 Thanks everyone. It seemed Firefox only deletes cookies after you are out of the Cookie dialog. 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.