Jump to content

cookie problems


contra10

Recommended Posts

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>

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.