Here is my code in which i am checking if session variable is not set then it will redirect to another page:
if (!isset($_SESSION)) {
session_start();
}
if (!isset($_SESSION['username']))
{
header("location: http://myweb.com/rel_notes/?page_id=779");
}
Problem: It is not redirecting to another page BUT if i change this line
header("location: http://myweb.com/rel_notes/?page_id=779");
to
die("You aren't allowed to access this page");
then it works. So Kindly tell me why it is not redirecting to another page?
EDIT: This is my whole code of that wordpress page im currently working on:
<?php
ob_start();
session_start();
if (!isset($_SESSION['username']))
{
header("location: http://myweb.com/rel_notes/?page_id=779");
exit();
}
if (isset($_POST["cancel"]))
{
if (!isset($_SESSION)) {
session_start();
}
session_unset();
session_destroy();
header("location: http://myweb.com/rel_notes/?page_id=779");
exit();
}
?>
<form method="post" enctype="multipart/form-data">
<div align="right">
<input class="btn btn-primary" type="submit" value="Log Out" name="cancel" id="cancel" style=""/>
</div>
</form>