0

I want to redirect to login.php when my session expired , i test with two pages , i logout in the first and the second will detect the expired session and also this page disconnected . i do this :

in my index.php i have :

    <script type="text/javascript">
$(document).ready(function(){

    setInterval(function() {
    $.post( "sessioncheck.php", function( data ) {
        if(data == "-1")
        {
            alert("Your session has been expired!");
            document.location = "login.php";
        }
    });
}, 3000);

});
</script>

and in sessioncheck.php i have :

session_start();

if(empty($_SESSION))
{
    //expired
    echo "-1";
}
else
{
    //not expired
    echo "1";
}

and in logout.php :

chdir("../../..");
include_once("config/config.php");
$_SESSION = array();
header("location:".__BACKURL."/login.php");

it's not working and i don't know were is the problem.

Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
hatane
  • 36
  • 6
  • Have you defined a name for your session? E.g.: `$_SESSION["user"]`. There is also nothing that destroys the session something like `unset($_SESSION)` or `session_destroy()` – node_modules Mar 30 '16 at 08:20
  • yes , i resolve the problem , it's in another file , thank's – hatane Mar 30 '16 at 08:31

0 Answers0