I've the following code to log out an user. I haven't touched this code since a while, and while it was working flawlessly earlier (and still works as expected when I run it on my localhost setup), even the header to redirect the webpage isn't working in this code now. Help please.
(session_start();
is present in the sar.php file which has been included.
<?php
$pageTitle = 'Log Out';
require_once('sar.php'); //Contains session_start();
require_once('navig.php');
?>
<div id="wrapper">
<div id="container2">
<div style="min-height: 370px">
<?php
if(isset($_SESSION['u_id'])) {
$_SESSION = array();
if(isset($_COOKIE[session_name()])) {
setcookie(session_name(), '' ,time()-9999);
}
session_destroy();
setcookie('rememberme', '', time()-9999);
setcookie('friend', '', time()-9999);
echo '<h2>You\'ve been logged out successfully.</h2>';
header('Refresh: 1; url= http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']));
}
else {
echo '<h2>You need to be logged in in order to be logged out. Right?</h2><br/>
<h3>Redirecting you to home in 3 seconds. 1.. 2.. 3.. Here you go.';
header('Refresh: 3; url= http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']));
}
?>
</div>
</div>
</div>
<?php
require_once('pair.php');
?>
The header doesn't redirect the page even if the user is not logged in. When the user is logged in, the cookies aren't cleared either, as I can see from Chrome's developer tools.
Edit: This page is online at http://www.recharged.in/logout.php