這是我整個的代碼,我遇到排隊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> 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找到,請幫忙,謝謝
這可能是StackOverflow上最常問的問題,請先搜索。 – Matt
作爲@Source Matters說,在實際的html代碼出來後,你不能發送設置cookie的頭文件。輸出前做檢查。而且,可能這裏有一個小錯誤,在?>和<?php(第2-3行)之間會出現迴應,我猜這也會阻止設置cookie和頭文件。 – Wizard