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
https://forums.phpfreaks.com/topic/57500-solved-small-logout-issue/
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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.