PHP-Code:
<?php
include_once '../inc/config.inc.php';
include_once './openxml.php';
ob_start();
session_start();
//check Login input with datbase
function executeLogin($username, $password) {
$xmldbase = xmlOpen('../'.USERDB);
$password = md5($password);
foreach($xmldbase->user as $key) {
$db_userId = $key->id;
$db_username = $key->username;
$db_userpw = $key->userpassword;
$db_lastlogin = $key->lastlogin;
$db_role = $key->role;
if($db_username == $username && $db_userpw == $password) {
$_SESSION['uid'] = uniqid($db_username, true);
$_SESSION['userid'] = $db_userId;
$_SESSION['username'] = $db_username;
$_SESSION['lastlogin'] = $db_lastlogin;
$_SESSION['userrole'] = $db_role;
header('Location:../index.php');
}
}
}
if (isset($_POST['username']) && isset($_POST['password'])) {
executeLogin($_POST['username'], $_POST['password']);
}
}
PHP-Code:
<?php
include './inc/config.inc.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo PAGEMAINTITLE; ?> :: LOGIN :: BACKEND</title>
<!-- CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet" />
<link href="../css/jquery-ui.min.css" rel="stylesheet" />
<link href="../css/style_be.css" rel="stylesheet" />
</head>
<body>
<div class="container" id="login">
<div class="row">
<div class="col-lg-12">
<form method="post" action="./function/loginHandler.php" class="form-control">
<fieldset class="form-control">
<label><?php echo PAGEMAINTITLE; ?> :: Login</label>
<label class="form-label" for="username">Benutzername</label>
<input index="1" class="form-control form-control-lg" name="username" type="text" id="username" required />
<label for="password">Passwort</label>
<input index="2" class="form-control form-control-lg" type="password" name="password" id="password" required />
</fieldset>
<input index="3" type="submit" class="form-control form-control-lg" name="submit" id="submit" value="Einloggen" />
</form>
</div>
</div>
</div>
</body>
</html>
PHP-Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ob_start();
session_start();
if (!isset($_SESSION['uid'])) {
header('Location:login.php');
exit;
}
?>
Nun werde ich, wenn ich mich einloggen möchte immer wieder auf die Login-Seite zurückgeworfen, was wohl daran liegen muss das die Session nicht funktioniert. Ich weiß leider keinen Rat mehr, darum frage ich hier mal nach.
Kommentar