The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automatic logout all userspice pages when one of them is logged out
#14
So, here is the javascript you can paste in the footer with the rest of the script tags (or wherever it will get executed on everypage...maybe you have a .js file you are already including or something):

http://pastebin.com/CiqVKuW0

And here is a PHP file you need to create and call users/helpers/logoutcheck.php (you can change the name, you can see the reference in the JavaScript code...just make sure they match). Also, you can set the check interval by replacing 5000 with something else (that is the time interval in milliseconds....5000 milliseconds = 5 seconds.

http://pastebin.com/9D5DKkiB

In your code you will need to change US_URL_ROOT to $us_url_root (I'm working on UserSpice 5 code base so that's why it is different).

Lastly, you need to create a hidden div or span that contains this text (again you can change it as you want, as long as the references all match) "Not Logged In" when $user->isLoggedIn()==False, and displays "Logged In" when the user is logged in. The HTML ID of this div or span needs to be set to "loginstatus" so the jQuery can find the right text and pass it to the PHP page.

Now, I'm not a JavaScript person, but this is how I solved the problem. The javascript function runs every 5 seconds, and when it runs, it executes the logoutcheck.php file with the string contents of the "loginstatus" hidden div. Inside the PHP file, it checks if $user->isLoggedIn() is false AND the string does not say "Not Logged In". If this is the situation, it means the user session has ended on another page, but the current page still says the user is "Logged In". This means the state of the page does not match the $user session state and it will run a redirect to the homepage ($us_url_root.'index.php'). Any other combination of states and it won't do anything.

This is a really crappy description and for that I apologize. See where you can get, and we can go from there.
  Reply


Messages In This Thread
Automatic logout all userspice pages when one of them is logged out - by brian - 09-23-2016, 06:55 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)