可能的重复:
php 标头已发送错误 https://stackoverflow.com/questions/3319207/php-headers-already-sent-error
我已附上我的代码,该代码用于 php 中的非常基本的登录。它给出了一个错误
无法发送会话 cookie - 标头
已发送(输出开始于
C:\xampp\htdocs\netsentries\f\includes\functions.php:1)
<?php
if (!isset($_POST['username'])) {
?>
<h3>Login</h3>
<form action="" method="post">
Username<br/>
<input name="username" type="text" /><br/>
Password<br/>
<input name="password" type="password" /><br/>
<input name="" type="submit" /><br/>
</form>
<?php
}
else
{
include('includes/config.php');
$data['username']= $_POST['username'];
$data['password']= md5($_POST['password']);
connect($db_name,$db_user,$db_pass,$db_host);
$query= "select * from user where username='" . $data['username'] . "' AND password='" . $data['password'] . "'";
$result=mysql_query($query);
//check that at least one row was returned
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0)
{
while($row = mysql_fetch_array($result))
{
session_start();
session_register($data['username']);
//successful login code will go here...
//echo 'Logged in!';
}
}
else
{
echo "Failed!";
}
}
?>
我无法找出问题所在
你不能session_start
当你输出任何 HTML 之后。移动session_start
调用顶部,并保留一个变量以供稍后回显的内容。任何不存在的东西<?php ?>
很重要,甚至是你的包含文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)