title: AJAX function to detect when session is expired and log out
body: <p>I have this function that checks if a session in the current tab has expired. However, if I open another tab and log out through there, my current tab won't know and somehow it maintains its session until I access an item from the navigation menu. Is there a way I can improve this by detecting when a user has either logged out or if the users session has expired? </p>
  
  <p>The main issue right now is if they open another tab and just log out from there.</p>
  
  <pre><code>function check_if_logged_in(){
      $.ajax({
          method: "POST",
          url: "&lt;?php echo site_url('Common/CheckSession'); ?&gt;",
          beforeSend: function () {
              $('.loading').show();
          },
          success: function(data){
              if(data==="undefined"||data===null||data===0){
                  console.log("logged out");
  //                window.location.replace("&lt;?php // echo BASE_URL;?&gt;");
              }else{
                  console.log("logged in");
              }
              $('.loading').fadeOut("slow");
          },
      });
  }
  </code></pre>
  
  <p>This is my checkSession function </p>
  
  <pre><code>public function checkSession(){
          if($this-&gt;logged_in()===false){
              echo false;
          }else{
              echo true;
          }
      }
  </code></pre>
  
  <p>this->logged_in() just checks if the session is still active.</p>
  
  <p>I have read about LocalStorage by HTML5. I'm wondering if this will affect mobile devices as the site itself is responsive and I've heard that iOS or some devices don't support LocalStorage.</p>