2015-03-02 44 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

相关问题