2015-03-02 59 views
1

我想在10分鐘後重定向頁面並清除會話值。 我實現了這個使用code.Any網頁在我的網站將10分鐘如何在幾分鐘後重定向頁面?

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

在我logout.php頁我的代碼清除會話值和現在重定向到index.php page.But後得到重定向我只得到重定向到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>"); 
    ?> 

回答

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

試試這個您的代碼似乎是正確的,它應該工作。您可以添加session_start()session_destroy()介於線

$_SESSION = array(); 

只是要確定會話變量被全殲。這不應該是需要的,這是session_destroy()應該做的。

如果它仍然不起作用,然後使用print_r($_SESSION)確保該會話正確設置在logout.php

+0

<?php session_start(); //刪除所有會話變量 session_unset(); $ _SESSION = array(); //銷燬會話 session_destroy(); /* echo(「」); * /如果我評論重定向代碼會話值被清除nw。 – user3386779 2015-03-02 06:20:05

+0

您也可以嘗試清除會話cookie,如['session_destroy()'](http://php.net/manual/en/function.session-destroy.php)文檔頁面上的示例#1中所述)。 – axiac 2015-03-02 07:11:38

+0

我無法使用頭重定向 – user3386779 2015-03-02 07:17:15

相關問題