Java:
<?php include "php/head.php"; ?>
<?php include "php/header.php"; ?>
<div class="aside"></div>
<div class="section">
<h1 class="title">Anmeldung</h1>
<?php
/*SchachfibelDAO wird in Session gespeichert*/
if (!isset($_SESSION["SchachfibelDAO"])) {
$_SESSION["SchachfibelDAO"] = $SchachfibelDAO;
}
/*Wird geprüft, ob Post existiert*/
if (array_key_exists("loggedUser", $_POST)) {
$username = htmlspecialchars($_POST["username"]);
$password = htmlspecialchars($_POST["password1"]);
$_SESSION["loggedUserId"] = $_SESSION["SchachfibelDAO"]->loginUser($username, $password);
if ($_SESSION["loggedUserId"] !== null) {
echo "Anmeldung war erfolgreich";
echo "<br> Du bist angemeldet als: " . htmlentities($_SESSION["SchachfibelDAO"]->getUser($_SESSION["loggedUserId"]));
} else {
echo "Anmeldung war nicht erfolgreich";
}
}
/*Wenn logout gepostet ist, der Nutzer ist ausgeloggt*/
if (array_key_exists("logout", $_POST) && isset($_SESSION["loggedUserId"])) {
$_SESSION["SchachfibelDAO"]->logoutUser($_SESSION["loggedUserId"]);
}
/*Wenn loggedUserId nicht existiert, ist der Nutzer ausgeloggt*/
if (!isset($_SESSION["loggedUserId"]) ) {
?>
<div class="anmeldung-container">
<div class="anmeldung-feld">
<form method="post">
<label for="nutzerName">Nutzername</label>
<input id="nutzerName" class="input" type="text" name="username" placeholder="Nutzername"/>
<div class="anmeldung-feld">
<label for="password">Password</label>
<input id="password" class="input" type="password" name="password1" placeholder="Password"/>
</div>
<input class="buttonAnm" type="submit" name="loggedUser" value="Anmelden">
</form>
<form action="./registration.php">
<input class="buttonAnm" type="submit" value="Registration">
</form>
<?php } else { ?>
<form method="post">
<input class="buttonAnm" name="logout" type="submit" value="Abmelden">
</form>
<?php } ?>
</div>
</div>
</div>
<?php include "php/footer.php"; ?>
wenn ich mich anmelde und dann die Seite aktualisiere oder wenn ich auf andere Seite gehe, wird Session immer gelöscht und automatisch meldet sich ab...
Woran könnte dass liegen?