尝试重定向页面时无法修改标头信息错误

时间:2015-06-19 05:57:03

标签: php twitter-bootstrap

我正在关注this视频教程,并且在登录页面将用户从home.php重定向到index.php的部分遇到了麻烦。当用户单击登录时,将检查凭据,并在调用head函数时弹出此错误:

  

"警告:无法修改标头信息 - 已发送的标头   (输出始于   /home/urbanas8/public_html/register/index.php:19299)in   第22行" /home/urbanas8/public_html/register/inc/header.inc.php;

第19299行只是

<?php require_once("./inc/header.inc.php");?>

和第22行是

header("location: home.php");

这是header.inc.php文件:

<?php 
            session_start();
            ini_set('display_errors', 1);
            error_reporting(E_ALL);
            require_once( "./inc/connect.inc.php" );


            if(isset($_POST['login'])){                 
                $user_login = strip_tags(@$_POST['user_login']);
                $password_login = strip_tags(@$_POST['login_password']);

                $password_login = md5($password_login);

                $sql = mysql_query("SELECT id FROM users WHERE email='$user_login' AND password='$password_login' LIMIT 1");
                $userCount = mysql_num_rows($sql);
                if($userCount == 1){
                    while($row = mysql_fetch_array($sql)){
                        $id = $row["id"];
                    }
                    //echo("pass");
                    //$_SESSION['user_login'] = $user_login;
                    header("location: home.php");
                    exit();
                }else {
                    echo("/invalid username/password");
                    exit();
                }
            }
    ?>
        <div id="top-bar">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <ul id="top-info">
                            <li>Phone: 703-518-4325</li>
                            <li>Email: <a href="mailto:info@urbanare.com">info@urbanare.com</a></li>
                        </ul>
                        <ul class="nav pull-right" id="top-buttons" style="line-height:10px !important;">
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-sign-in"></i>Log in<strong class="caret"></strong></a></a>
                                <ul id="login-dp" class="dropdown-menu" style="padding: 15px;">
                                    <form action="" method="POST" accept-charset="UTF-8">
                                        email: <input id="user_username" style="margin-bottom: 15px;" type="text" name="user_login" size="30" />
                                        password: <input id="user_password" style="margin-bottom: 15px;" type="password" name="login_password" size="30" />
                                        <input id="user_remember_me" style="float: left; margin-right: 10px;" type="checkbox" name="remember" value="1" />
                                        <label class="string optional" for="user_remember_me"> Remember me</label>
                                        <input class="btn btn-primary" style="clear: left; width: 100%; height: 32px; font-size: 13px;" type="submit" name="login" value="Sign In" />
                                    </form>
                                </ul>
                            </li>

                            <li class="divider"></li>

                            <li><a href="../register"><i class="fa fa-pencil-square-o"></i> Register</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="sticky-wrapper"><div id="nav-section">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <a href="http://comingsoon.safepropserv.com/landing/index.html" class="nav-logo"><img src="./files/logo_transparent.png" alt="UrbanaRE Logo"></a>

                        <!-- BEGIN SEARCH -->
                        <div id="sb-search" class="sb-search">
                            <form>
                                <input class="sb-search-input" placeholder="Search..." type="text" value="" name="search" id="search">
                                <input class="sb-search-submit" type="submit" value="">
                                <i class="fa fa-search sb-icon-search"></i>
                            </form>
                        </div>
                        <!-- END SEARCH -->

                        <!-- BEGIN MAIN MENU -->
                        <nav class="navbar">
                            <button id="nav-mobile-btn"><i class="fa fa-bars"></i></button>

                            <ul class="nav navbar-nav">
                                <li class="dropdown">
                                    <a href="./files/UrbanaRE -- Property Info.html" data-toggle="dropdown" data-hover="dropdown">Home<b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="http://comingsoon.safepropserv.com/landing/index.html">Home Search</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/index-slider.html">Home Slider</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/index-grid.html">Home Grid</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/index-map.html">Home Map</a></li>
                                    </ul>
                                </li>

                                <li class="dropdown">
                                    <a href="./files/UrbanaRE -- Property Info.html" data-toggle="dropdown" data-hover="dropdown">Properties<b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="http://comingsoon.safepropserv.com/landing/properties-detail.html">Properties Detail</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/properties-list.html">Properties List</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/properties-grid.html">Properties Grid</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/properties-grid2.html">Properties Grid 2</a></li>
                                    </ul>
                                </li>

                                <li class="dropdown">
                                    <a class="dropdown" href="./files/UrbanaRE -- Property Info.html" data-toggle="dropdown" data-hover="dropdown">Pages<b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="http://comingsoon.safepropserv.com/landing/about.html">About Us</a></li>
                                        <li class="dropdown-submenu">
                                            <a href="./filse/UrbanaRE -- Property Info.html">Agency</a>
                                            <ul class="dropdown-menu">
                                                <li><a href="http://comingsoon.safepropserv.com/landing/agency-detail.html">Agency Detail</a></li>
                                                <li><a href="http://comingsoon.safepropserv.com/landing/agency-listing.html">Agency Listing</a></li>
                                            </ul>
                                        </li>
                                        <li class="dropdown-submenu">
                                            <a href="./files/UrbanaRE -- Property Info.html">Agent</a>
                                            <ul class="dropdown-menu">
                                                <li><a href="http://comingsoon.safepropserv.com/landing/agent-detail.html">Agent Detail</a></li>
                                                <li><a href="http://comingsoon.safepropserv.com/landing/agent-listing.html">Agent Listing</a></li>
                                            </ul>
                                        </li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/pricing-tables.html">Pricing Tables</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/login.html">Login</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/register.html">Register</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/faq.html">FAQ</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/404.html">404</a></li>

                                        <li class="divider"></li>
                                        <li><a tabindex="-1" href="./files/UrbanaRE -- Property Info.html"> Separated link </a></li>
                                    </ul>
                                </li>

                                <li class="dropdown">
                                    <a href="./files/UrbanaRE -- Property Info.html" data-toggle="dropdown" data-hover="dropdown">Blog<b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="http://comingsoon.safepropserv.com/landing/blog-detail.html">Blog Detail</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/blog-listing1.html">Blog Listing 1</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/blog-listing2.html">Blog Listing 2</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/blog-listing3.html">Blog Listing 3</a></li>
                                        <li><a href="http://comingsoon.safepropserv.com/landing/blog-listing4.html">Blog Listing 4</a></li>
                                    </ul>
                                </li>

                                <li><a href="http://comingsoon.safepropserv.com/landing/contacts.html">Contacts</a></li>
                            </ul>

                        </nav>
                        <!-- END MAIN MENU -->

                    </div>
                </div>
            </div>
        </div></div>

    <!-- END HEADER -->

3 个答案:

答案 0 :(得分:1)

根据您分享的错误消息。

输出在&#34; index.php:19299&#34; (在包括header.inc.php之前)

如果你没有任何空格(在ob_start()之前;在index.php文件的第一行。

<?php ob_start();

答案 1 :(得分:1)

您应该尝试在以下行注释:

  //       ini_set('display_errors', 1);
     //       error_reporting(E_ALL);

或者您应该检查标题中是否应该回显。因为在标题重定向之前回显某些内容时,通常会发生此错误。

答案 2 :(得分:0)

删除了session_start();从标题中将其放在索引文件的顶部... 3小时后。