2016-02-07 30 views
1

這是我整個的代碼,我遇到排隊header('location:../registrar/dasboard.php');PHP - 錯誤不能修改標題信息

一個錯誤的說法, 警告:不能更改頭信息,頭部已經發送

下面

是我的全部代碼

<?php 
session_start();?> 
<?php include('header.php'); 
php include('navbar.php'); 
php include('footer.php')?> 
    <div class="container"> 
     <div class="margin-top"> 
      <div class="row"> 
<center> 
     <img src="../kcwa/kingsway.jpg" class="img-rounded"> 
</center> 
       <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" autofocus 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> 
           </form> 

           <?php 
           if (isset($_POST['submit'])){ 
           $username = $_POST['username']; 
           $password = $_POST['password']; 
           $query = "SELECT * FROM users WHERE username='$username' AND password='$password'"; 
           $result = mysql_query($query)or die(mysql_error()); 
           $num_row = mysql_num_rows($result); 
            $row=mysql_fetch_array($result); 
            if($num_row > 0) { 
             header('location:/registrar/dasboard.php'); 
           $_SESSION['id']=$row['user_id']; 
            } 
            else{?> 
           <div class="alert alert-danger">Access Denied</div>  
           <?php 
           }} 
           ?> 
       </div> 
      </div>  
      </div> 
     </div> 
    </div> 

我嘗試過其他解決方案,但我can'f找到,請幫忙,謝謝

+0

這可能是StackOverflow上最常問的問題,請先搜索。 – Matt

+0

作爲@Source Matters說,在實際的html代碼出來後,你不能發送設置cookie的頭文件。輸出前做檢查。而且,可能這裏有一個小錯誤,在?>和<?php(第2-3行)之間會出現迴應,我猜這也會阻止設置cookie和頭文件。 – Wizard

回答

1

在嘗試標題重定向之前,不能向瀏覽器輸出任何HTML。錯誤很明顯。如果您想在它之前重定向並輸出HTML,則必須使用客戶端方法,例如JavaScript window.location()。

0

我還沒有測試。但嘗試像這樣。只需將表單提交php代碼放在表單頂部即可。還有下面的代碼。在include函數之前,你不需要指定php。

 php include('navbar.php'); 

就這樣說吧。

 include('navbar.php'); 

嘗試這可能它會工作。

相關問題