标题已发送,找不到问题 [英] Headers Already Sent, cannot find issue

查看:107
本文介绍了标题已发送,找不到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

已由PHP发送的头文件

好吧,一个拥有管理面板的脚本,并且一切正常。我移动了服务器,现在代码打破了。我一直在Google上搜索,并且在任何打开/关闭php标签之前没有空格,我有ob_start(); &安培; ob_end_flush()函数; session_start()之前和之后,但我仍然收到错误。任何人都可以找到哪里出了错?

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();
    ?>

我一直收到2个错误(主目录路径被忽略):

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

    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所以我仍然在亏损。任何想法?

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?

在此先感谢。

推荐答案

你的问题我看到<?php 之前的空格。 <?php 之前的任何内容都被视为输出,并且在发送之前不应发送任何内容。 s

Even here in your question I see spaces before <?php. Anything before <?php is treated as an output, and you shouldn't have anything sent before you send headers

如果<?php 之前的4个空格不是这种情况 - 请查找文件中的BOM字符。

If 4 spaces before <?php is not the case - look for the BOM character in the file.

这篇关于标题已发送,找不到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆