可能重复:
PHP 已发送的标头
好的,所以我制作了一个带有管理面板的脚本,一切运行良好。我移动了服务器,现在代码中断了。我整天都在谷歌搜索,在任何打开/关闭 php 标签之前都没有空格,我有 ob_start(); & ob_end_flush(); 在 session_start() 之前和之后,但我仍然遇到错误。谁能找到我哪里出错了?
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$ref = null;
if ($_POST['ref'])
{
$ref = $_POST['ref'];
}
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$myusername = stripslashes(mysql_real_escape_string($myusername));
$mypassword = stripslashes(mysql_real_escape_string($mypassword));
$sql="SELECT * FROM `$tbl_name` WHERE `username`='$myusername' and `password`='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$dt2=date("Y-m-d H:i:s");
function getip()
{
$ip = null;
if (isset($_SERVER["REMOTE_ADDR"])){$ip = $_SERVER["REMOTE_ADDR"];}
else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];}
else if (isset($_SERVER["HTTP_CLIENT_IP"])){$ip = $_SERVER["HTTP_CLIENT_IP"];}
return $ip;
}
$myperms = null;
while ($row = mysql_fetch_array($result)) {
$myperms = $row['perms'];
}
mysql_query("UPDATE admins SET `lastlogin`='".$dt2."',`lastip`='".getip()."', state='1' WHERE username='".$myusername."'");
mysql_query("UPDATE settings SET `lastadmin`='".$myusername."',`lastadminip`='".getip()."'");
session_start();
$_SESSION['username'] = $myusername;
$_SESSION['permissions'] = $myperms;
if ($ref)
{
header("location:admin.php?list=".$ref);
}
else
{
header("location:admin.php");
}
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
我不断收到 2 个错误(主目录路径无效):
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at admin/checklogin.php:1) in admin/checklogin.php on line 47
和
Warning: Cannot modify header information - headers already sent by (output started at admin/checklogin.php:1) in admin/checklogin.php on line 56
我不知道为什么它在新服务器上而不是旧服务器上这样做。谷歌上的另一篇文章说“一些主机在发送标头之前不喜欢 html”,但我在这个文件中没有任何 html,所以我仍然不知所措。有任何想法吗?
提前致谢。