Ich habe mehrere Web-Artikel und stackoverflow Antworten durchsucht, aber ich kann den Fehler in meinem Code nicht finden. Vielleicht habe ich es zu lange angeschaut.
Im Grunde bin ich nur eine einfache Anmeldung für eine Demonstration einrichten, ja, ich weiß es injizierbar und veraltet, das spielt keine Rolle. Im Grunde benutze ich eine Anmeldung mit Sitzungen und leite dann den Benutzer zu sicherem Inhalt um, wenn sie eingeloggt sind. Ich habe auch ein Skript erstellt, das nach den Sitzungsvariablen sucht, um zu sehen, ob der Benutzer angemeldet ist oder nicht. Im Grunde schlüge ich ein totes Pferd und ich weiß nicht, warum das nicht funktioniert, könnte jemand bitte helfen?
index.php:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome, please log in</title>
<link href="../css/admin.css" rel="stylesheet" type="text/css">
</head>
<body>
<?PHP require_once"scripts/mysql_connect.php"; // Establish a database connection ?>
<div id="admin_top">
<div id="admin_logo"></div>
</div>
<div id="admin_login_box">
<H1 style="margin-left: 20px;">Please log in</H1>
<hr><br>
<?PHP
echo "<form method='post' action='checklogin.php' name='loginform'>
<input type='email' name='aEmail' placeholder='Your Email Address' required><br>
<input type='password' name='aPassword' placeholder='Password' required><br><br>
<input type='submit' value='Log In'>
</form>"
?>
</div>
</body>
</html>
checklogin.php:
<!doctype html>
<html>
<head>
<title>Checking login...</title>
<link href="../css/admin.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="admin_top">
<div id="admin_logo"></div>
</div>
<div id="admin_login_box">
<?php
require_once"scripts/mysql_connect.php";
$aEmail = $_POST['aEmail'];
$aPassword = $_POST['aPassword'];
$md5Password = MD5($aPassword);
$sql = "SQL";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$active = $row['active'];
$count = mysql_num_rows($result);
// If result matched, table row must be 1 row.
if($count == 1) {
$_SESSION["login"] = "OK";
$_SESSION["aEmail"] = $aEmail;
echo "<h1>Log in successfull!</h1>
<hr><br />
Your details checked out! Redirecting you now...";
// Wait 1 seconds then redirect to the secure content.
header("Location: http://www.website.com/secure_content.php");
} else {
echo "<h1>Log in unsuccessfull!</h1>
<hr><br />
Sorry. It seems your log in detials were incorrect. Please go back and try again.";
// Wait 2 seconds then redirect back to the log in page.
header("Location: http://www.website.com/index.php");
}
exit;
?>
</div>
</body>
</html>
loginstatus.php:
<?php session_start();
if(!(isset($_SESSION["login"]) && $_SESSION["login"] == "OK")) {
header("Location: http://www.website.com/index.php");
exit;
}
?>
Vielen Dank für jede Hilfe!
session_start sollte über jedes Script gehen, das Sie verwenden, und nicht nur loginstatus.php –
add 'session_start();' auf jeder Seite '(.php)' on top –
Sie können 'header (" Location: ...) 'nachdem du etwas in die Ausgabe geschrieben hast, verschiebe den Haken oben auf der Seite vor deinem' ' – apokryfos