1

I'm using the JavaScript below to check if the user session has not expired (with PHP) at intervals of 5 seconds. After logging out from another tab (same browser) or which the current session must have expired, still the code is bringing up the alert("Logged back in."); which is supposed to work for active sessions.

setInterval(function () {
    var checklogin = "<? if ($this->session->userdata('user_logged_in')) {echo '1';} else {echo '0';} ?>";
    if (checklogin == "1" ){
        alert("Logged back in.");
    } else {
        alert("you are already logged out!");
    } 
}, 5000);

Please what am I doing wrong ?

rgettman
  • 176,041
  • 30
  • 275
  • 357
getapay
  • 11
  • 2

1 Answers1

0

The php section of your code will not change at run time. You could, for example, perform an AJAX call to your server to retrieve session information.

EDIT:

If you're using jQuery, take a look at: jQuery Ajax

If without jQuery, take a look at: How to make an ajax call without jquery?

Community
  • 1
  • 1
grim
  • 6,669
  • 11
  • 38
  • 57
  • how can i perform an AJAX call to the server pls? so, it will be run at interval, with the code ?? – getapay May 29 '14 at 05:34