Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 登录系统-标题(位置:)赢得';t重定向到受限页面_Php_Mysql_Phpmyadmin_Login System - Fatal编程技术网

Php 登录系统-标题(位置:)赢得';t重定向到受限页面

Php 登录系统-标题(位置:)赢得';t重定向到受限页面,php,mysql,phpmyadmin,login-system,Php,Mysql,Phpmyadmin,Login System,因此,我试图构建一个登录和注册系统,但当提交登录表单时,除了“header(Location:restricted.PHP)”之外,所有PHP似乎都运行良好。什么都没有发生,没有错误显示,当我点击提交页面只是刷新 以下是登录页面的代码: <?php include("connection.php"); if (isset ($_POST["submit"]) ) { $email = $_POST["email"];

因此,我试图构建一个登录和注册系统,但当提交登录表单时,除了“header(Location:restricted.PHP)”之外,所有PHP似乎都运行良好。什么都没有发生,没有错误显示,当我点击提交页面只是刷新

以下是登录页面的代码:

<?php 
        include("connection.php");

        if (isset ($_POST["submit"]) ) {

            $email = $_POST["email"];
            $password = $_POST["password"];

            $result = mysqli_query($conn, "
                SELECT * FROM users WHERE email = '$email' AND password = '$password'
            ");

            $row = $result->fetch_array(MYSQLI_BOTH);

            session_start();
            $_SESSION["UserID"] = $row["UserID"];
            $_SESSION["first_name"] = $row["first_name"];
            $_SESSION["last_name"] = $row["last_name"];
            $_SESSION["email"] = $row["email"];
            $_SESSION["username"] = $row["username"];
            $_SESSION["password"] = $row["password"];

            header('Location: restricted.php');

        }

    ?>

<!DOCTYPE html>
<html>

<?php 

$title = "Sign In";
$css = "";

include('../include/head.php');
?>


<body>

<h2>Log In</h2>

<!--LOGIN FORM-->   
<form action="signin.php" method="POST">
    Email <input type="text" name="email" /> <br />
    Password <input type="password" name="password" />
    <br /> <br />

    <input type="submit" name="submit">
</form>

<a href="signup.php">Sign Up</a>

</body>
</html>

登录
电子邮件
密码

以下是受限页面的代码:

<?php 
    session_start();
    if ( isset($_SESSION["UserID"] ) ) {

    } else {
        header('Location: signin.php')
    } 
?><!DOCTYPE html>

<html>    
<head>
    <title>Restricted Page</title>
</head>

<body>
    <p><?php echo 'Welcome ' . $_SESSION["first_name"]; ?></p>
</body>
</html>

限制页

非常感谢您的帮助。

错误: 如果在发送头之后忘记终止脚本,那么还应该在头中使用HTTP/1.1所述的绝对路径

header("Location: http://example.com/restricted.php");
exit();

退出(标题(“位置:http://example.com/restricted.php"));

Restricted.php在第6行也需要同样的东西

笔记: 如前所述,使用php函数进行散列


这是非常不安全的,您需要在将密码存储到数据库之前对其进行哈希处理,这可以防止访问您的数据库的黑客看到它们,访问纯文本密码的管理员也很糟糕。

您确实应该使用PHP来处理密码安全性。是的,将其哈希存储在数据库中,然后在登录时再次查询数据库之前散列密码。您需要添加
exit()
就在重定向之后。@PatrickMurphy如果使用PHP提供的
password\u verify()
函数,则不必在登录时散列密码。阅读随附的教程,了解其工作原理。@Patrick Murphy谢谢!但它似乎仍然不起作用当我点击提交时,我不会被重定向到受限页面,我只是停留在登录页面上。我在/Users/…../signin.php的第19行收到以下错误:警告:session_start():无法发送会话缓存限制器-已发送的标头(输出从/Users/…../signin.php:1开始)警告:无法修改标头信息-已发送的标头(输出从/Users/…../signin.php:1开始)在第27行的/Users/…../signin.php中有什么想法吗?再次感谢:)将
会话_start()
移到
包含“connection.php”上方的最开始处如果仍然存在此问题,则需要研究输出缓冲