简体   繁体   中英

How to check login session status using ajax and php?

I have this code which checks for session status.Everything is right about this code but it doesn't redirect me to the login.php page,Please help me.Where have i gone wrong?

function checkLoginStatus() {
    jQuery.ajax({
            type: "POST",
            url: "checkstatus.php",
            success: function(res){
                if(res == "0") {
                     window.location = "login.php"; 
                }
            }
    });
}

// checkstatus.php

 <?php
  session_start();
  if(isset($_SESSION["email"]))
  {
     echo "1";
  } else {
     echo "0";
  }
 ?>

This should do it for you:

window.location.href = "/login.php";

As far as your login-page is reachable over http://yourdomain.com/login.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM