php - 提交登录后显示空白页

标签 php login error-handling

我的代码有问题
但是用用户名和密码提交后,我得到空白页,
我试图制作一个登录系统,但是在提交表单时出现了一个问题,该表单仅显示为空白白页

在我的脚本下方,名称为 login.php

<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<title>Login</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<style>
        body {
            background-color:#eee;
        }
        .row {
            margin:100px auto;
            width:300px;
            text-align:center;

        }
        .login {
            border-radius: 5px;
            background-color:#fff;
            padding:20px;
            margin-top:20px;
        }
    </style>
<body>
<div class="container">
        <div class="row">
<?php
if(isset($_POST['submit'])){
include 'db.php';
$user=addslashes($_POST['user']);
$pass=md5($_POST['pass']);
$cari= "select user from guru where user='$user' and pass='$pass'";
$query= mysql_query($cari);
$num=mysql_num_rows($query);
if($num>0){ 
session_register('user');
$row= mysql_fetch_array($query);
$_SESSION['user']=$row['user'];
header("location:index.php");
exit;
 } else {
 echo '
 <div class="alert alert-danger" role="alert">User atau password salah.</div>';
};
}
?>
<div class="login">

<div class="panel panel-info" >
                    <div class="panel-heading">
                        <div class="panel-title">Masuk</div>

                    </div>     

                    <div style="padding-top:30px" class="panel-body" >

                        <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>

                        <form id="loginform" class="form-horizontal" role="form" action="" method="post">

                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                        <input id="login-username" type="text" class="form-control" name="user" value="" placeholder="username">                                        
                                    </div>

                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                        <input id="login-password" type="password" class="form-control" name="pass" placeholder="password">
                                    </div>






                                <div style="margin-top:10px" class="form-group">
                                    <!-- Button -->

                                    <div class="col-sm-12 controls">
                                      <input type="submit" name="submit" class="btn btn-primary btn-block" value="Masuk" />


                                    </div>
                                </div>



                            </form>     



                        </div>                     
                    </div>


    </div>


</body>
</html>

最佳答案

您必须在start_session()之后添加ob_start();

当您在成功登录 header 之后重定向页面之前编写html代码时,由于 header 已经发送,因此不会重定向页面。

ob_start将用作存储html代码的缓冲区,并且如果您显式发送它或文件末尾,则将呈现html代码/发送 header

关于php - 提交登录后显示空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41713257/

相关文章:

php - 验证以 '&' 和一个单词结尾的逗号分隔列表的正则表达式是什么

php - 检查用户组是否存在

php - 防止SQL盲注

login - 使用 MVC 在 Sitecore 7.1 中实现自定义登录

login - 如何通过代码将登录项添加到山狮 osx

c++ - 不断收到 "see declaration of ' 类“错误

json - Laravel 5.1自动完成功能给Symfony fatal error

c - execvp() - exit() 函数中的返回值

php - 大型 HTML 表单 - 用户体验和可访问性

Grails 简单的注册/登录表单