我收到关于“头已经发送”错误,当我成功登录到页面中。
这里是我的代码与登录交易:
<?php
include("config.php");
$eUsername = $_POST['username'];
$ePassword = $_POST['password'];
$con = mysql_connect("localhost","MY_USERNAME","MY_PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("forum", $con);
$result = mysql_query("SELECT * FROM members WHERE username = '$eUsername'");
while($row = mysql_fetch_array($result))
{
if ($ePassword==$row['password']) {
echo "Correct";
setcookie("loggedIn", "true", time()+1000000000);
setcookie("logUsername", "$eUsername", time()+100000000);
setcookie("logPassword", "$ePassword", time()+100000000);
}
else {
echo "Incorrect username/password. Please try again.";
}
}
mysql_close($con);
if ($_COOKIE['loggedIn']=="true") {
$curURL=basename($_SERVER['SCRIPT_NAME']);
echo "You are already logged in. <a href='$curURL?lo=true'>Log out?</a>";
}
echo "<br /><br />";
print_r($_COOKIE);
?>
所以基本上这是什么做的是,如果你用正确的信息登录,将设置3个曲奇,您的用户名,密码和一个检查另外两个。
但是当我做成功登录,我得到这些错误:
警告:不能更改头信息 - 头已经发出(输出开始/home/scott/web/forum/index.php :18)in /home/scott/web/forum/index.php on line 19
警告:无法修改标头信息 - 已经发送的标头(在/home/scott/web/forum/index.php处开始输出:18)/home/scott/web/forum/index.php在线20
警告:不能更改头信息 - 头已经SE NT在/home/scott/web/forum/index.php(输出开始/home/scott/web/forum/index.php:18)第21行
我在做什么错?
首先,我希望你喜欢SQL注入,因为你已经有了它。其次,你应该哈希你的密码。 – Kalium 2010-07-06 23:06:27
删除了SQL相关标签,因为标头仅限于HTTP。 – 2010-07-06 23:10:54
更不用说将实际密码存储在数据库及其cookie中。有史以来最差的安全性。 – animuson 2010-07-06 23:11:03