Jump to content

[SOLVED] small logout issue


L

Recommended Posts

Hello,

When I login, i have two sessions stored and two cookies(for the remember me feature). So when I click on logout I terminate the cookies, and kill the sessions, but when I go back to the index the part of the script that is to be shown when a user is logged in shows and the part that is to be shown when a user is not logged in. Maybe I'm not terminating correctly? I'm not sure but here's the  code.

<?
session_start(); 
include("database.php");

if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
   setcookie("cookname", "", time()-60*60*24*100, "/");
   setcookie("cookpass", "", time()-60*60*24*100, "/");
   cookie("cookname", $_SESSION['username'], null);
cookie("cookpass", $_SESSION['password'], null);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>Infinite Vortex</title>
<meta http-equiv="content-type" content="text/html; charset=us-ascii" />
<link rel="stylesheet" type="text/css" href="/newmain.css" />
<link rel="stylesheet" type="text/css" href="/newupdate.css" />
<script type="text/javascript" src="/extternal.js">
</script>
<script type="text/javascript" src="/updatepic.js">
</script>
</head>
<body>

				<!-- END Banner -->

<div class="border">
					<!-- START Banner -->

				<!-- END Banner -->
<?php include("menu.php"); ?>
<div class="left">
<?

if((empty($_SESSION['username'])) || (empty($_SESSION['userid']))) {
   echo "<h1>Error!</h1>\n";
   echo "You are not currently logged in, logout failed. Back to <a href=\"index.php\">index</a>";
}
else{
   /* Kill session variables */
   unset($_SESSION['username']);
   unset($_SESSION['userid']);
   $_SESSION = array(); // reset session array
   session_destroy();   // destroy session.

   echo "<h1>Logged Out</h1>\n";
   echo "You have successfully <b>logged out</b>. Back to <a href=\"index.php\">index</a>";
}

?>
		</div>
	</div>
</div>
	<?php include("footer1.php"); ?>

Thank you for your time,

~L

 

 

EDIT: username: test and pass: test [login, then logout and you can see the problem when you click the link back to the index.]

Link to comment
Share on other sites

wow...i feel pathetic...the problem was quite simple. I was indeed doing everything right, except on my login i had

   if((empty($_SESSION['username'])) || (empty($_SESSION['userid']))) {
  
     echo'
     <form action="" method="post">

     <table align="left" border="0" cellspacing="0" cellpadding="3">
       <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30" /></td></tr>
       <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30" /></td></tr>
    <tr><td>Remember Me:<input type="checkbox" name="remember">
<input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr>
     </table>

     </form>';
     
}

if ($_SESSION != NULL || isset($_SESSION) ) {
echo "Logged In<br />";
  echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <br><br>"."<a href=\"cp.php?user=$_SESSION[username]\">My Account</a><br />";
  echo "<a href=\"logout.php\">Logout</a>";
  }
?>



 

You guys can already see the mistake....i need to make the last two ifs one if else statement, so now it fixed....

This is SOLVED!

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.