This topic is locked

Auditing users login and logout

8/1/2006 05:47:32
PHPRunner General questions
rjks author

Hallo,
I have an audit table in which userers logins are kept.
I would like to keep track of when Users logout as well, The login audit is done with events aftersuccessfullogin.
The logout button is as follows

<a href="#" onclick="document.forms.logout.submit();return true;"><?php echo mlang_message("LOG_OUT");?></a>


How can I audit this, with an event??
Robert

Alexey admin 8/1/2006

Robert,
here is the code for Login OnLoad event to audit logouts

if($_REQUEST["a"]=='logout')

{

// put your code here

}


Please note that this code won't keep track of logouts when the user just closes its browser.

rjks author 8/2/2006

Robert,

here is the code for Login OnLoad event to audit logouts
Please note that this code won't keep track of logouts when the user just closes its browser.


Morgen Alexey,
I tried the above with no result, the if clause wasn´t called.
I changed it for this in the event and added a parameter for the Userid in the login.php

LOGIN EVENT
function LoginOnLoad($tmpUserID)

{

if (@$_POST["action"] == 'logout' || @$_POST["a"] == 'logout')

{

$b_info = "Abmeldung erfolgt!";

write_logout(9,"'".$tmpUserID."'",$b_info,0,"System erzeugt");}
}
LOGIN.PHP
if(@$_POST["a"]=="logout" || @$_POST["action"]=="logout" ||!@$_SESSION["MyURL"])

{

$tmpUserID = $_SESSION["UserID"];

session_unset();

}


The reason is in the Login.php session_unset() is called before the onload event and the UserID isn´t available anymore.
The $_REQUEST didn´t seem to work so I changed it for the $_POST Variables, I had to check both action and a otherwise not every logout would have been audited.
QUESTION Have I missed a POST Variable?
Thanks again for the tip with the login onload event.
Robert