This topic is locked

Add custom code to run when user clicks Logout

8/26/2007 5:14:55 PM
PHPRunner General questions
J
jbartc author

Using PHPRunner 4.1 Build 300. Can anyone point me to the spot where I could insert some custom code to run when the user clicks Logout? I would like to insert some information into a table when this occurs. I realize that it will not run if the user doesn't click Logout to leave - I can live with that. Thanks in advance.

A
alang 8/26/2007

This action will trigger the LoginOnLoad event but the downside is that it will also be triggered when you first login. You can't use SESSION variables to distinguish as the SESSION variables are unset by the logout action so not sure whether this helps. I note that cookies are also set by the logout so I guess it might be possible to use this fact to determine the difference between initial login and subsequent logout??

J
Jane 8/27/2007

John,
you can use LoginOnLoad event for this purpose.

Here is a sample:

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

{

//your code

}

J
jbartc author 8/27/2007

John,

you can use LoginOnLoad event for this purpose.

Here is a sample:


Jane:
Thank you for this idea. However, the code does not seem to execute at all with the if statement in place. If I delete the if statement, the code does execute. As expected, however, it executes whenever the login page is loaded, not just when the user clicks logout. Any suggestions?

Alexey admin 8/28/2007

John,
unfortunately you can not use events in this case.

Find this lines in generated login.php file:

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

{



and insert your custom code just after.

J
jbartc author 9/7/2007

John,

unfortunately you can not use events in this case.

Find this lines in generated login.php file:
and insert your custom code just after.


Alexey:
Thank you for this information - it is exactly what I needed.

A
alang 9/13/2007

Another option to avoid having to edit generated code is to add some code to the commonfunctions module - this is at the top level and not inside a function:
$selfs = explode("/",$_SERVER["PHPSELF"]);

$pr = $selfs[1]; // This is project name

$pgs = explode(".",$selfs[2]); // strip filename and extension

$pg = $pgs[0]; // This is page with possible extension added by PHPRunner
// Following few lines with credit to topic #5699

$subpg = strrchr($pg,'
'); if($subpg !== false)

$pg = substr($pg,0,-strlen($subpg));
// Check for login/logout page

if($pg == "login")

{

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

echo "<h1>LOGOUT TRAPPED HERE</h1>"; // debug line - replace with appropriate actions

}