Log out script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manton
Forum Newbie
Posts: 10
Joined: Fri Apr 27, 2007 8:27 am
Location: Athens

Log out script

Post by manton »

Hello,
I use Dreamweaver and I used the built in "logout user" option. It works on FF but not on IE.
Any help would be really appreciated since Im a noob and its difficult for me to find out what is wrong.

Code: Select all

<?php require_once('../Connections/palso.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
session_start();
$var = $_SESSION['MM_Username'];
require_once('../Connections/palso.php');


$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_palso, $palso);
$query_Recordset1 = sprintf("SELECT * FROM `data` WHERE SchoolCode = '%s' ORDER BY `data`.`LevelDescription` ASC, `data`.`Surname` ASC", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $palso) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 session_start();
$_SESSION['ses_kod'] = $_POST['txtkod']; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7" />
<title>&#932;&#945;&#958;&#953;&#957;&#972;&#956;&#951;&#963;&#951; &#965;&#960;&#959;&#968;&#951;&#966;&#943;&#969;&#957; &#945;&#957;&#940; &#949;&#960;&#943;&#960;&#949;&#948;&#959;</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
</head>

<body>
<div id="container">
<div id="list">
<form id="form1" name="form1" method="get" action="tickets.php">
<input class="nav" type="submit" name="Submit" value="&#917;&#956;&#966;&#940;&#957;&#953;&#963;&#951; &#916;&#949;&#955;&#964;&#943;&#969;&#957;" />
<a href="<?php echo $logoutAction ?>"><input class="nav" type="submit" name="Submit" value="&#913;&#960;&#959;&#963;&#973;&#957;&#948;&#949;&#963;&#951;" />
</a>

<table width="800" border="1">
  <tr>
    <td width="50" class="fields"><a href="list.php">LevelDescription</a></td>
    <td width="100" class="fields"><a href="list_bin.php">BinSerialCode</a></td>
    <td width="320" class="fields"><a href="list_sur.php">Surname</a></td>
  </tr>
    <?php do { ?>
      <tr>
        <td class="calign"><?php echo $row_Recordset1['LevelDescription']; ?></td>
        <td class="calign"><?php echo $row_Recordset1['BinSerialCode']; ?></td>
        <td><?php echo $row_Recordset1['Surname']; ?></td>
        <td><?php echo $row_Recordset1['Name']; ?></td>
        <td><?php echo $row_Recordset1['Fathername']; ?></td>
      </tr>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

I dont know what dreamweaver is doing You can use this to log out.

Code: Select all

session_start();
$_SESSION = array();
//Also delete the Session Cookie
if(isset($_COOKIE[session_name()]))
  {
     setcookie(session_name(), '', time()-42000, '/');
  }
session_destroy();
You can also use session_unset
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

What's happening in IE that you know its not working? Does the session not get unset, do you get a blank page, etc?

Wayne
manton
Forum Newbie
Posts: 10
Joined: Fri Apr 27, 2007 8:27 am
Location: Athens

Post by manton »

I found out what is wrong...
I have two submit buttons on one form :roll:
Post Reply