php登录可以脱机工作,但不能联机

php登录可以脱机工作,但不能联机,php,Php,大家好,我是PHP新手。我查了w3c,得到了一些好的提示。然而,我的登录代码有一个小挑战。它在第8行的/home/perspect/public\u html/jst/dbcon.PHP:2中显示PHP警告:无法修改标题信息-标题已由(输出开始于/home/perspect/public\u html/jst/index.PHP)发送 下面是我的索引页 <?php session_start(); include_once 'includes/dbcon.php'; if(isset($

大家好,我是PHP新手。我查了w3c,得到了一些好的提示。然而,我的登录代码有一个小挑战。它在第8行的/home/perspect/public\u html/jst/dbcon.PHP:2中显示PHP警告:无法修改标题信息-标题已由(输出开始于/home/perspect/public\u html/jst/index.PHP)发送 下面是我的索引页

<?php
session_start();
include_once 'includes/dbcon.php';

if(isset($_SESSION['user'])!="")
{
    header("Location: candidate_list.php");
}

if(isset($_POST['btn-login']))
{

    $username = mysqli_real_escape_string($con, $_POST['username']);
    $password = mysqli_real_escape_string($con, $_POST['password']);
    $stat = 'notvoted';

    $res=mysqli_query($con,"SELECT * FROM students WHERE username='$username' AND status='$stat'");
    $row=mysqli_fetch_array($res);

    if($row['password']==md5($password))
    {
        $_SESSION['user'] = $row['user_id'];
        header("Location: candidate_list.php");
    } 
    else
    {
        ?>
        <script>alert('wrong details');</script>
        <?php
    } 

}
?>
<!-- Login Box -->
                            <div class="col-md-6 col-md-offset-3 col-sm-offset-3">
                                <form class="login-page" action="" method="post">
                                    <div class="login-header margin-bottom-30">
                                        <h2>Login</h2>
                                    </div>
                                    <div class="input-group margin-bottom-20">
                                        <span class="input-group-addon">
                                            <i class="fa fa-user"></i>
                                        </span>
                                        <input placeholder="VIN" name="username" class="form-control" type="text">
                                    </div>
                                    <div class="input-group margin-bottom-20">
                                        <span class="input-group-addon">
                                            <i class="fa fa-lock"></i>
                                        </span>
                                        <input placeholder="Password" name="password" class="form-control" type="password">
                                    </div>
                                    <div class="row">

                                        <div class="col-md-6">
                                            <button class="btn btn-primary pull-right" type="submit" name="btn-login">Login</button>
                                        </div>
                                    </div>
                                    <p> 
                                </form>
                            </div>
                            <!-- End Login Box -->

警报(“错误的详细信息”);
登录
登录

我的candidate_list.php代码是

<?php
session_start();
include_once 'includes/dbcon.php';

if(!isset($_SESSION['user']))
{
    header("Location: index.php");
}
$res=mysqli_query($con, "SELECT * FROM students WHERE user_id=".$_SESSION['user']);
$userRow=mysqli_fetch_array($res);
?>

我的dbcon是

  <?php

$con=mysqli_connect("xxx","xxx","xxxx","xxx");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

?>


感谢您的帮助。

一旦您在头重定向之前回显某些内容,这种类型的php警告就会出现

如果您仍然想重定向,可以使用ob_start或javascript


window.location.href=path是否尝试更改此行:
isset($\u会话['user'])=“
by
isset($\u SESSION['user'])
?刚刚尝试过,但仍然不起作用快速检查-在
之前是否有空格
之前是否真的有空格没有空格,只是检查一下这个想法确实帮了我的忙。。谢谢