Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法登录,没有错误消息_Php_Login - Fatal编程技术网

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

Php 无法登录,没有错误消息,php,login,Php,Login,我想登录,但我不能。用户和密码的注册是正常的,但当我尝试登录时,什么也没有发生,也没有错误消息 这是my 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";

我想登录,但我不能。用户和密码的注册是正常的,但当我尝试登录时,什么也没有发生,也没有错误消息

这是my 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>

用户名

我无法在帖子上回复,因为我没有代表,但我们开始:

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

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

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


希望它有帮助

它是否重新定向到index.php页面?是的,它重定向到index.php文件。如果这样做不正确,现在添加echo“Hello,World”;在索引中。php@user2421425您缺少>
会话_start()
<这需要在所使用的每个文件的顶部和内部,在
@Fred下面,这是正确的,除非他已经在config.phpI中调用了session_start(),已经有一个logout.php文件,但这是我的错误。现在问题解决了。非常感谢。