无法登录,也没有错误消息

时间:2013-08-01 01:40:24

标签: php login

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

这是我的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>

1 个答案:

答案 0 :(得分:0)

我不能回复帖子,因为我没有代表,但我们去了:

“抱歉,我一直在尝试,但是使用session_start();它会直接转到index.php而无需登录 - user2421425 1分钟前”

因为你已陷入困境,尝试使用以下命令创建一个logout.php:

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

希望有所帮助

相关问题