contra10 Posted March 2, 2009 Share Posted March 2, 2009 sometimes when i click logout my cookie does not die heres my scripts Sets Cookie <?php // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); header("Location: http://localhost/main/"); ?> if cookie is already set <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: http://localhost/main/"); } } } ?> header for pages <?php //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); $in = mysql_query("SELECT username FROM users WHERE username ='$username'") or die (mysql_error()); $in2 = mysql_query("SELECT id FROM users WHERE username ='$username'") or die (mysql_error()); while($info = mysql_fetch_array( $check )) while($row = mysql_fetch_assoc($in)) while ($row2 = mysql_fetch_assoc($in2)) { ?> logout <?php $past = time() - 100; //this makes the time in the past to destroy the cookie setcookie(ID_my_site, gone, $past); setcookie(Key_my_site, gone, $past); header("Location: http://localhost/"); ?> <html> <head><title>Thanks</title> </head> <body> <h1>You've Logged Out</h1> </body> </html> Quote Link to comment Share on other sites More sharing options...
WolfRage Posted March 2, 2009 Share Posted March 2, 2009 At first looking over your code I thought maybe it was a Undefined Constant issue, however I think you did define these constants, but you have left out that code and more. This makes it hard to troubleshoot your code. Please post the script more completely. Of course leave out the actual values for the constants. Also make your subtraction from time larger it won't hurt. Finally is "gone" defined? 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.