所以,我正在創建一個SQL登錄系統,我想我會從一些簡單的事情開始,比如檢查用戶名和密碼,然後返回你到右上角的問候主索引。
我做了所有這些,並且它應該按照我所看到的工作,但是當我提交登錄表單時,服務器會拋出一個HTTP Error 500 (Internal Server Error)
。 我希望能在這裏得到一些幫助,因爲我的IRC朋友一直沒能找到解決方案。登錄系統包含2個文件,並且它們的內容:
的index.php:
PHP簡單登錄系統 - 500錯誤
<!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();
}
} ?>
我找不到任何錯誤我的代碼,我希望有人會。任何幫助表示讚賞。
再次感謝您,但現在它似乎沒有做任何事情。加載並重新加載索引頁需要很長時間.. – Kinz 2012-04-15 15:08:05
您能否更新您的文章中的代碼,以便我們可以查看您的更改? – Jeffrey 2012-04-15 15:13:05
已更新,縮進更好。 – Kinz 2012-04-15 15:16:02