简体   繁体   English

自动刷新 div 中的 PHP 重定向

[英]PHP redirection in an autorefresh div

I'm stuck with php redirection after session_destroy.在 session_destroy 之后,我被 php 重定向卡住了。 I make an auto refresh in some element.我在某些元素中进行了自动刷新。 I write my code like this:我这样写我的代码:

navigation.php (after login success): navigation.php(登录成功后):

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

index.php:索引.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:页脚.php:

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

function.php: 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: 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 .所以,我认为我的问题出在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:如果当 API 返回而不是“200”时,它将破坏所有 session 并重定向到登录页面,但它变得失败,因为我的登录页面显示在容器正文中,如下所示: 在此处输入图像描述

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();可以通过使用 javascript window.location解决,然后通过session_destroy();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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