简体   繁体   中英

PHP redirection in an autorefresh div

I'm stuck with php redirection after session_destroy. I make an auto refresh in some element. I write my code like this:

navigation.php (after login success):

<?php
  session_start();
  $token = $_SESSION['token'];
?>
<html>
<head>
   <title>....</title>
   ...... CSS/JS.......
</head>
<div class="menu">
    ..... MY WEB MENU ......
</div>

index.php:

<?php
   include "navigation.php";
   include "function.php";
?>
<body>
  <div class="container">
     <div class="load_data">
         <?php
            include "load_data.php";
         ?>
     </div>
  </div>
</body>
<?php
  include "footer.php";
?>

footer.php:

</html>
<script>
   $(function() {
       setInterval(function(){
          $('.load_data').load('load_data.php');
       },5000);
   });
</script>

function.php:

<?php
   function A($token){
      global $data_counter;

       .... CALL API BY cURL BASED ON TOKEN .......

       if($result == "200"){
            $data_counter = count($decode['data']);
       }else{
          if (session_destroy()) { 
            header("location:../");
            exit();
         }
      }
   }
?>

load_data.php:

<?php
  include_once("function.php");
  A($token)

  ..... DO SOME OPERATION AFTER GET RESULT FROM FUNCTION A ......      
?>

So, I think my problem is in function.php . If when the API return instead of "200" it will destroy all session and redirect to login page, but it become failed because my login page show in the container body like this: 在此处输入图像描述

Does anyone know what should I change?

I've figure it out. It can be solved by using javascript window.location then clear the session by session_destroy();

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