I am creating 3 sessions and destroying with proper functions. However it throws weird issue to me where in Internet explorer, it doesn't destroy session, in firefox and chrome, I have to refresh the page twice. Here is the simple code I am using to check:
login.php (This is to create sessions)
if(isset($_POST['create_session'])){
$_SESSION['user_id'] = '1';
$_SESSION['first_name'] = 'first name';
$_SESSION['last_name'] = 'last name';
echo "Session Created Successfully! Click <a href='index.php'>here</a>";
}
?>
<form method="post" action="">
<input type="submit" value="Create Session" name="create_session">
</form>
index.php (This is to check whether session has been created properly or not)
<?php
session_start();
echo "<pre>";print_r($_SESSION);
echo "<a href='logout.php'>logout</a>";
?>
logout.php (This is how I destroy the session)
<?php
session_start();
session_destroy();
session_write_close();
header("location:login.php");
?>
Functions I have tried with referring stackoverlow itself are as blow:
- session_cache_limiter("nocache");
- session_cache_expire(0);
- session_write_close();
- ob_flush();
However none of the solution worked.
I am using cloudsites from liquid web to host above code, in case any one has faced same issue from same service provider. Their support says they use opcache engine in cloud, in case opcache is the reason, not sure about that.
It's a deadlock for me to host a project, so right solution will be really helpful.