我正在使用php会话,当我更改页面时, 似乎 正在调用嵌入式代码。添加嵌入代码时,会导致我的注销功能出现异常,从而导致注销功能就像用户注销而不是像用户登录一样。
的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.');
}
这是第二页。调用此页面时应该发生的是它将我重定向到Index.php,而是重定向到Login.php。但是,如前所述,当我删除嵌入代码时,此页面正常运行。
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 */
}
?>