PHP头问题 [英] php header problem

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

问题描述

你能帮我吗?

我转移到新的主机,而我suddnley收到此错误:

i transfer to a new hosting and i suddnley getting this error:

警告:无法修改标头信息-第25行的/home/capital/public_html/Google/CheckLogin.php中已经发送过的标头(输出始于/home/capital/public_html/Google/Connect.php:1)

Warning: Cannot modify header information - headers already sent by (output started at /home/capital/public_html/Google/Connect.php:1) in /home/capital/public_html/Google/CheckLogin.php on line 25

这是我的脚本:

<?php
    session_start();
    $server = 'localhost';
    $user = '***';
    $pass = '***';
    $db = '***';

    // Connect to Database
    $connection = mysql_connect($server, $user, $pass) or die ("Could not connect to server ... \n" . mysql_error ());
    mysql_select_db($db);


    $my_t=getdate(date("U"));
    $DateTime = ("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]");

    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];


    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql=mysql_query("SELECT * FROM Users WHERE Username='$myusername' and Password='$mypassword' and status='1'")or die(mysql_error());
    if(mysql_num_rows($sql) > 0){
        while($count=mysql_fetch_array($sql)){
            $_SESSION['user']=$count['userid'];
            $TodayLogin = $count['TodayLogin'];
        }
        mysql_query("UPDATE Users SET LastLogin = '$TodayLogin' WHERE userid = '$_SESSION[user]'"); 
        mysql_query("UPDATE Users SET TodayLogin = '$DateTime' WHERE userid = '$_SESSION[user]'"); 
        header("location:index.php");

    }
    else
    {
        echo "<div style='text-align:center;font-family:arial;font-size:32px;font-weight:bold;'>user or password incorrect</div>";
    }
?>

推荐答案

检查是否在<?php 标记之前没有任何内容.

check that you dont have anything before the <?php tag.

问题是,如果您在开始标记之前有任何东西然后将其翻译为html并与标题一起发送,然后再创建页面的其余部分.稍后,您尝试在已发送一个头之后再发送另一个头.

the problem is that if you have anything before the start tag then it get translated to html and sent with the header before the rest of the page is created. later you try to send another header after one already was sent.

我发现可以遵循以下步骤:

i found this steps to follow:

1)查找导致问题的header()语句.错误必须在此行或之前.

1) Find the header() statement that is causing the problem. The error must be at or before this line.

2)在此标头语句之前查找所有可能将输出发送给用户的语句.

2) Look for any statements that could send output to the user before this header statement.

如果找到一个或多个,请找到某种方法将标头语句移到它们之前.复杂的条件语句可能会使问题复杂化,但也可能有助于解决问题.

If you find one or more, find some way to move the header statement before them. Complex conditional statements may complicate the issue, but they may also help solve the problem.

在PHP脚本的顶部考虑一个条件表达式,该条件表达式尽早确定标头值并将其设置在那里.

Consider a conditional expression at the top of the PHP script that determines the header value as early as possible and sets it there.

3)确保php开始和结束标记之外没有空白.虽然<?php 开始标记之前的空白行可能看起来是无害的,但是当由PHP处理时,它将变成打印出空白行的echo语句.这是常见的罪魁祸首.

3) Make sure there is no white space outside of the php start and end tags. While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit.

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

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