sc_user_logout , cant make it work, example

Hi,
In SC8,
After sometime I am trying to logout the user, i think the right macro is “sc_user_logout” but couldnt make it work.

Trying to make it work in “onexecute” event in the menu app. but it writes
“Fatal error: Call to undefined function sc_user_logout()” also i didnt understand the parameters of the macro ? first one is the user we want to logged out !?, second one is ? 3rd and 4th ?

Any idea ?

Thanks,
caga

Hello,

The macro scope inform you the applications and events which this macro can be used:
http://www.scriptcase.net/docs/en_us/v8/scriptcase-macros/scriptcase-macros#sc_user_logout

Oh Thank you , i missed that !

Then whats is best event to logout the user after some timeout ? I choose the menu/onexecute event because of its frequent trigger but scope doesnt let that!
This is a classic menu driven multi app platform with security module.

Just a few steps… this will logout a user and return them to the login screen if they are inactive for more than 10 minutes (and they try and do something)…

  1. Set up a couple of global vars in your security module’s “login” app (in onApplicationInit event) - mine is “sec_Login” - yours may be the same or “app_Login” or whatever:
// Define session idle time in minutes
[idle_time] = 10;
[last_active_time] = time();

[idle_time] is up to you - but this is where you define the timeout period in minutes

  1. Then put this code in a library.
<?php

    function check_idle_time($idle_interval) {
        // Function to query the current time and compare it against the last active time.
        // If the time is greater than the passed idle time (minutes) then log out, forcing a
        // re-login - if not exceeded "reset" the last active time to now....
        
        $time_diff = (time() - [last_active_time]) / 60;	    // Idle time in minutes
		
	if ($time_diff > $idle_interval) {
	    // Idle time exceeded limit, then logout
	    sc_redir(sec_Login, "", "_parent");        // Replace 'sec_Login' with your login app's name if different
	} else {
            // Still within idle time limit - reset start time
	    [last_active_time] = time();			
	}

    }		
?>

Then in every app’s onLoad event (or equivalent event when onLoad not a valid event) call:

check_idle_time([idle_time]);

Make sure also that in every app that you make this call that under Programming -> Libraries you tick your newly added library

1 Like

Thanks adz1111, great !

I tried and want to comment few things ;

  • I prefer to put the function only once in Menu/onexecute event, in my platform you have to click on the menu for every move, so i think suitable

  • I used date instead of time, nothing much but, ( also did not try with the time variable but … ) when it’s near midnight i think the difference can be wrong ! But because of this I discovered that date1-date2 is not the difference in seconds ! You have to use convert function like this :

(strtotime(date2) - strtotime(date1) ) -> this gives difference in seconds.

again thanks for the clues.
caga

1 Like

Glad I could help