所以,我正在制作一个 SQL 登录系统,我想我会从一些简单的东西开始,比如检查用户名和密码的 IF,然后将您返回到主索引,并在右上。
我做了所有这一切,它应该从我看到的情况下工作,但是当我提交登录表单时,服务器会抛出一个HTTP Error 500 (Internal Server Error)
. 我希望我能在这里得到一些帮助,因为我的 IRC 朋友一直无法找到解决方案。登录系统包含2个文件,其内容为:
index.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Kinz</title>
<?php session_start(); ?>
<link rel="stylesheet" href="stylesheet.css">
<meta name="description" content="Kinz's personal website." />
<meta name="keywords" content="kinz,php,login,fruity,css" />
<meta name="author" content="Kinz" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="mainbar">
<label class="menubar">Home</label>
<?php if ($_SESSION['loggedin'] == false || isset($_SESSION['loggedin']) == false) { ?>
<form id="loginform" action="auth.php?login=true" method="POST">
<input type="submit" class="login" id="login" name="loginSubmit" value="Login">
<input type="password" class="login" id="password" name="password" value="Password">
<input type="text" class="login" id="username" name="username" value="Username">
</form> <?php } elseif ($_SESSION['loggedin'] == true) { ?>
<label id="loginWelcome">Welcome, <?php echo $_SESSION['user']; ?>!</label> <?php } else { echo "Error."; } ?>
</div>
<div id="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</body>
</html>
auth.php:
<?php session_start();
$user = preg_replace("/[^a-zA-Z1-9]/", '', $_POST['username']);
$pass = preg_replace("/[^a-zA-Z1-9]/", '', $_POST['password']);
$hpass = md5($pass);
if (isset($_POST['loginSubmit']) && $_GET['login'] == "true") {
if ($user == "Admin" && $pass == "Password123") {
$_SESSION['loggedin'] = true;
$_SESSION['user'] = $user;
header("Location: index.php"); exit();
} else {
print("<h1><b>Login failure.</b></h1>"); sleep(10);
header("Location: index.php"); exit();
}
if (!$_SESSION['loggedin']) {
header("Location: index.php"); exit();
} else {
header("Location: index.php"); exit();
}
} ?>
我在我的代码中找不到任何错误,我希望有人会。任何帮助表示赞赏。