I try to save the username into a session called $_SESSION['Username'] when the admin is logging in. On my localhost it's working fine, but on the server it is not. I also tested if SESSIONS can be saved in general and it is working, even over multiple sites. Also the $_SESSION['example'] is working fine and I can reach it on other sites of the server.
The $_SESSION['test1'] and $_SESSION['test2'] also won't be saved so I guess it's not even reaching the if-statements.
The password I tested is also correct.
   <?php
session_start();
/*if (isset($_SESSION["Username"])) {
    header('location: dndStill.php');
    exit;
}
*/?>
<!DOCTYPE html>
<html>
<head>
    <title>Anmelden</title>
    <link rel="stylesheet" type="text/css" href="css/galleryLogin.css">
</head>
<body>
<div class="loginAll">
    <form action="loginGallery.php" method="post" class="loginForm">
        <div class="loginFeld">
            <input type="text" name="username" placeholder="Nutzername" required>
        </div>
        <div class="loginFeld">
            <input type="password" name="password" placeholder="Passwort" required>
        </div>
        <div class="input-group">
            <button type="submit" class="login" name="submit">Login</button>
        </div>
    </form>
</div>
<?php
if (isset($_POST["submit"])) {
    require_once "dbconnect_simple.php";
    $username = ($_POST['username']);
    $password = ($_POST['password']);
    $password = md5($password);
    $query = "SELECT * FROM nutzer WHERE nutzername= ? AND passwort= ? LIMIT 1";
    $stmt = $mysqli->prepare($query);
    $stmt->bind_param("ss", $username, $password);
    $stmt->execute();
    $result = $stmt->get_result();
    if (mysqli_num_rows($result) == 1) {
        while($row = $result->fetch_array()) {
            if ($password === $row["passwort"]) {
                $_SESSION["Username"] = $row["nutzername"];
                //header("Location: dndFood.php");
            } else {
                echo'Falsches Passwort oder Nutzername';
                $_SESSION['Fehler 1'] = "Fehler1";
            }
        }
    } else {
        echo 'Falsches Passwort oder Nutzername';
        $_SESSION['Fehler 2'] = "Fehler2";
    }
}
?>
<?php '<pre>' ;
$_SESSION['example'] = "example";
print_r($_SESSION);
'</pre>';
?>
</body>
</html>
 
    