登录页面看起来没有重定向到下一页我该如何解决这个问题?

时间:2015-05-07 07:13:39

标签: php

登录页面看起来没有重定向到下一页如何解决这类问题?登录页面看起来没有重定向到下一页仍然坚持index.php页面如何修复此错误....我认为会话是问题?

的index.php

<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
    <div class="container">
        <div class="margin-top">
            <div class="row">   
            <div class="span12">

                <div class="login">
                <div class="log_txt">
                <p><strong>Please Enter the Details Below..</strong></p>
                </div>
                        <form class="form-horizontal" method="POST">
                                <div class="control-group">
                                    <label class="control-label" for="inputEmail">Username</label>
                                    <div class="controls">
                                    <input type="text" name="username" id="username" placeholder="Username" required>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="inputPassword">Password</label>
                                    <div class="controls">
                                    <input type="password" name="password" id="password" placeholder="Password" required>
                                </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                    <button id="login" name="submit" type="submit" class="btn"><i class="icon-signin icon-large"></i>&nbsp;Submit</button>
                                </div>
                                </div>

                                <?php
                                if (isset($_POST['submit'])){
                                session_start();

                                $username = $_POST['username'];
                                $password = $_POST['password'];
                                $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
                                $result = mysqli_query($dbcon, $query)or die(mysql_error());
                                $num_row = mysqli_num_rows($result);
                                    $row=mysql_fetch_array($result);
                                    if( $num_row > 0 ) {
                                        header('location:../admin_uplbcdc/dashboard.php');
                                $_SESSION['id']=$row['user_id'];
                                    }
                                    else{ ?>

                                <div class="alert alert-danger">Access Denied</div>     
                                <?php
                                }}
                                ?>
                        </form>

                </div>
            </div>      
            </div>
        </div>
    </div>
<?php include('footer.php') ?>

dashboard.php

<?php require_once('../db/dbcon.php'); ?>
<?php include('../admin_uplbcdc/session.php'); ?>
<?php include('../admin_uplbcdc/header_2.php'); ?>
<?php include('../admin_uplbcdc/navbar.php'); ?>
    <div class="container">
        <div class="margin-top">
            <div class="row">
                    <?php include('../admin_uplbcdc/head.php'); ?>
                <div class="span2">
                    <?php include('../admin_uplbcdc/sidebar.php'); ?>
                </div>
                <div class="span10" align="center">
                <br/> <br/> 
                    <?php include('../admin_uplbcdc/slider.php'); ?>
                </div>      
          </div>

        </div>
    </div>
      <?php include('footer.php'); ?>       

1 个答案:

答案 0 :(得分:0)

正确设置错误报告并查看警告。

如果之前有任何输出,则无法使用header启动会话或重定向,请将session_start移至PHP脚本的顶部。

<强>的index.php

<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<?php

session_start();

if (isset($_POST['submit'])) {
    // all PHP code goes here
}

?>

HTML goes here