Logout Problems with PHP

Asked

Viewed 25 times

0

I am trying to create a code for the user to close the browser, logout to run.

This is my Logout file.

session_start();
$_SESSION = array();
session_destroy();
header("Location:index.html");

I tried to use an onunload (below) to force the logout after the user leaves the page.

<body onunload="logout.php">

This way did not work, so I tried this way (below) and also did not work

<script>
function logout(){
          window.location.href ='logout.php';
      }
</script>
<body onunload="logout();">

  
  • Take a look at all the comments and the answer to this question and see if it helps you: https://answall.com/questions/430234/onbeforeunload-no-google-chrome-alguma-solu%C3%a7ao/430238#430238

1 answer

0

Hello, taking a look at your question I came across the following post.

Remembering that you must leave return null.

window.onbeforeunload = closingCode;
function closingCode(){
   // Coloque o código aqui...
   return null;
}

https://stackoverflow.com/questions/13443503/run-javascript-code-on-window-close-or-page-refresh

On the execution of your code, once closed the browser the session is destroyed.

One suggestion is to set a time of the last user action with the session id and thus force to log in again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.