Reputation: 7175
I want to redirect a page after 10 minutes and clear the session values. I achieved this using the code.Any page in my website will get redirect after 10 minutes
<META HTTP-EQUIV="refresh" CONTENT="600;URL=logout.php?timeout">
In my logout.php page I have the code for clearing session values and redirect to index.php page.But now I get only redirect to index.php page and session value is not destroy.
<?php
session_start();
// remove all session variables
session_unset();
// destroy the session
session_destroy();
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.location.href='index.php';
</SCRIPT>");
?>
Upvotes: 1
Views: 972
Reputation: 72206
Your code seems correct and it should work. You can add the line
$_SESSION = array();
somewhere between session_start()
and session_destroy()
just to be sure the session variables are wiped. It shouldn't be needed, this is what session_destroy()
is supposed to do.
If it still doesn't work then use print_r($_SESSION)
to be sure the session is properly set in logout.php
.
Upvotes: 1
Reputation: 1834
You can try this by using refresh header the in php like
<?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);
?>
Upvotes: 1