【问题标题】:How to redirect a page after few minutes?几分钟后如何重定向页面?
【发布时间】:2015-05-02 10:09:30
【问题描述】:

我想在 10 分钟后重定向页面并清除会话值。 我使用代码实现了这一点。我网站中的任何页面都会在 10 分钟后重定向

<META HTTP-EQUIV="refresh" CONTENT="600;URL=logout.php?timeout">

在我的 logout.php 页面中,我有清除会话值并重定向到 index.php 页面的代码。但是现在我只重定向到 index.php 页面并且会话值没有被破坏。

       <?php
       session_start();
       // remove all session variables
       session_unset(); 

       // destroy the session 
       session_destroy(); 
       echo ("<SCRIPT LANGUAGE='JavaScript'>
       window.location.href='index.php';
       </SCRIPT>"); 
    ?>

【问题讨论】:

    标签: php html session


    【解决方案1】:

    您的代码似乎正确,应该可以工作。您可以添加行

    $_SESSION = array();
    

    介于session_start()session_destroy() 之间,只是为了确保会话变量被擦除。它不应该是必需的,这是session_destroy() 应该做的。

    如果仍然无法正常工作,请使用print_r($_SESSION) 确保会话在logout.php 中正确设置。

    【讨论】:

    • window.location.href='index.php'; "); */ 如果我评论重定向代码会话值被清除 nw.
    • 您也可以尝试清除会话cookie,如session_destroy()文档页面上的示例#1所述。
    • 我无法使用标头重定向
    【解决方案2】:

    您可以通过使用 php 中的刷新标头来尝试此操作 喜欢

    <?php
         /*in this refresh is in second you can define it as your requirement*/
         $sec=6000;
         header( "Refresh:$sec; url=http://www.example.com/page2.php", true, 303);
    ?>
    

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 2021-07-22
      • 2016-02-20
      相关资源
      最近更新 更多