-1

我想登录,但我不能。用户和密码的注册没问题,但是当我尝试登录时没有任何反应,也没有错误消息。

这是我的 index.php 中的代码:

<?php
require_once("config.php");
if (isset($_SESSION['username']) === FALSE){
header('location:login.php');
exit();
}
$where = "";
$sql = "SELECT id,subject FROM notes LIMIT 30";
$result = mysql_query($sql);
?>

这是 login.php 文件的代码:

<?php
require_once("config.php");
$message = '';
$username = '';
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$username = mysql_real_escape_string(trim($_POST['username']));
$password = sha1($_POST['password']);

$sql = "SELECT * from users 
where username ='" . $username . "' 
and password = '" . $password . "'";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
$_SESSION['username'] = $username;
header("location:index.php");
} else {
$message = "Unable to login.  Check your username and password and try again.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form method ="POST" action="login.php">
<?php
if ($message != '') {
echo $message;
}
?>
<table>
<tr>
<th>username</th>
<td><input type="text" name="username" value ="<?php echo $username; ?>"/>
</tr>
<tr>
<th>password</th>
<td><input type="password" name="password" />
</tr>
</table>
<input type="submit" value="Login"/> &nbsp; <a href="registration.php"> register </a>
</form>
</body>
</html>
4

1 回答 1

0

由于我没有代表,我无法回复该帖子,但我们开始了:

“抱歉,我一直在尝试,但使用 session_start();它无需登录就直接将我带到 index.php – user2421425 1 分钟前”

由于您已登录,请尝试使用以下命令创建 logout.php:

<?
session_start();
session_destroy();
header('location:index.php');
?>

希望有帮助

于 2013-08-01T02:08:12.280 回答