Possible Duplicate:
Headers already sent by PHP
Ok, so I made a script that has an admin panel, and all was working well. I moved servers and now the code breaks. i've been googling all day and there are no spaces before any opening/closing php tags, i have ob_start(); & ob_end_flush(); before and after the session_start() and yet i'm still getting errors. Can anyone find where ive gone wrong?
<?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();
?>
I keep getting 2 errors (home directory path nulled out):
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
and
Warning: Cannot modify header information - headers already sent by (output started at admin/checklogin.php:1) in admin/checklogin.php on line 56
I can't figure out why it does this on the new server but not the old. Another post on google said "some hosts dont like html before the header is sent" but i don't have any html in this file so im still at a loss. any ideas?
Thanks in advance.