Skip to main content
January 24, 2012
Answered

Please help inserting current time on logout

  • January 24, 2012
  • 1 reply
  • 904 views

This is how I log out:

$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 = "index.php";

  if ($logoutGoTo) {

    header("Location: $logoutGoTo");

    exit;

  }

}

Waht I need is to insert the current time in the DB on logout.

This is my query:

$query = "UPDATE eu45antinew.t_usuario SET  `usuario_exitTime`= NOW() WHERE usuario='$loginUsername'";

$result = mysql_query($query) or die(mysql_error());

...but where should I place it?

Thanks

This topic has been closed for replies.
Correct answer

OK. When I said anywhere before the redirect, I was thinking about something closer to it   You don't want to log the time until you have verified that logout was requested, right. So put it just before you set the session variables to null. But that's probably not your problem. It would help to see the entire page code.


Sorry, my mistake...

I was using the wrong where clause like this:

$query = "UPDATE eu45antinew.t_usuario SET `usuario_exitTime`= NOW() WHERE usuario='$loginUsername'";

instead of like this:

$query = "UPDATE eu45antinew.t_usuario SET `usuario_exitTime`= NOW() WHERE usuario='$colname_admin_login_RS'";

it works perfect now.

Thanks Bregent

1 reply

Participating Frequently
January 24, 2012

You can put it anywhere before the redirect.

January 24, 2012

Thanks but I've tried putting my query in different places before the redirect with no luck.

Here's an example:

// ** Logout the current user. **

$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
$query = "UPDATE eu45antinew.t_usuario SET  `usuario_exitTime`= NOW() WHERE usuario='$loginUsername'";
$result = mysql_query($query) or die(mysql_error());


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 = "index.php";

  if ($logoutGoTo) {

    header("Location: $logoutGoTo");

    exit;

  }

}

Participating Frequently
January 24, 2012

>Thanks but I've tried putting my query in

>different places before the redirect with no luck.

No luck means...?