При запуске сайте логин равен guest, если ввести user1 и авторизоваться всё как бы ок, но если 2 раза перезапустить сайт, то выполниться код, как будто нажал на выйти, хотя не нажимал никуда и логин станет guest1. Почему выполнятся php код, когда он не должен выполняться
HTML
<?php
include_once "php/session.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Testing</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<input type="text" id="login">
<button id="btn" onclick="singin();">Sign In</button>
<button id="btn" onclick="singout();">Sign Out</button>
<p id="login_enter"></p>
<script>
var str = '<?php echo $_SESSION['login'];?>';
document.getElementById("login_enter").innerHTML = str;
function singin () {
var login = document.getElementById('login').value;
jQuery.ajax({
url: "php/server.php",
type: "POST",
dataType: "html",
data: "login="+login,
success: function(response) {
document.getElementById("login_enter").innerHTML = response;
},
error: function(response) {
}
});
}
function singout () {
<?php $_SESSION['login'] = "guest1"?>
str = '<?php echo $_SESSION['login'];?>';
document.getElementById("login_enter").innerHTML = str;
console.log("exit");
}
</script>
</body>
</html>
PHP server
<?php
require "session.php";
$login = "";
$FORM['login'] = "";
if (isset($_POST['login'])) $FORM['login'] = htmlspecialchars($_POST['login']);
$login = $FORM['login'];
if ($login == "user1") {
$_SESSION['login'] = "user1";
echo $_SESSION['login'];
} else {
echo "Такого пользователя нету";
}
?>
PHP session
<?php
session_start();
if (!isset($_SESSION['login'])) {
$_SESSION['login'] = "guest";
}
?>