如何在几分钟后重定向页面?

时间:2015-03-02 05:40:35

标签: php html session

我希望在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>"); 
    ?>

2 个答案:

答案 0 :(得分:1)

你可以在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);
?>

答案 1 :(得分:1)

您的代码似乎正确无误。您可以添加

$_SESSION = array();

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

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

相关问题