prasad chinthala prasad chinthala - 1 year ago 81
PHP Question

How to display login page with back button after logout?

After logout again if user clicks on the browser back button then the previous page showing again instead of login page. I am using a wordpress method called "wp_logout_url() " as a logout url. can anyone out there please help me in this. Thanks in advance.

Answer Source

You need to use session variable for login and logout. More Details on PHP Session

Use below code to check for session variable

      if(!isset($_SESSION['login'])) : 
      header("Location: login.php");  

When user logout, simply unset the login session variable, and destroy the session as below.


Also if you want to disable the back button using javascript. I found here something useful for you.

history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download