I am using php session and it seems the embedded code is being called when I am changing pages. When adding the embedded code it causes my logout function to misbehave, resulting in the logout function acting as if the user is logged out instead of acting like the user is logged in.
Index.php:
<a href="inc/Log_in_out.php"><button>Login/Logout</button></a>
...
var x;
function timedCount() {
if (isLogged == 1) {
x = setTimeout(function(){TimeMeOut();}, timeLeft*1000);
}
}
function TimeMeOut() {
//Embeded PHP Code being called
// Removing this code makes the logout work perfectly fine
<?php
//Set session empty
$_SESSION['user'] = '';
// remove all session variables
session_unset();
// destroy the session
session_destroy();
?>
location.reload();
alert('You where logged out.');
}
Here is the second page. What should happen when this page is called is that it redirects me to Index.php but instead I am redirected to Login.php. However like mention before when I remove the embedded code this page functions as normal.
Log_in_out.php:
<?php
session_start();
if(isset($_SESSION['user'])) {
/* When Already Logged In*/
//Set Cookie to false
$_SESSION['user'] = '';
// remove all session variables
session_unset();
// destroy the session
session_destroy();
//change page
header("Location: http://cornelis.website/GeoLocationSite/Index.php"); /* Redirect browser */
} else {
/* When user is logged out*/
header("Location:http://cornelis.website/GeoLocationSite/Login.php"); /* Redirect browser */
}
?>