on localhost redirect工作于hostgator错误无法修改头信息(php)

时间:2012-10-03 12:08:50

标签: php

我有这段代码:

<?php
    //Search logic for Holiday.GE
    $search_variables = $_GET['s']. '+' .$_GET['cat'];
    $var_lang_now = $_GET['lang_current_search'];

        if ($var_lang_now == ru OR $var_lang_now == en) {
            $refering_page = 'http://dev.holiday.ge/' . $var_lang_now . "/";
        } else {
            $refering_page = 'http://dev.holiday.ge';
        }

    //This sends http post to url without curl
    header("Status: 301 Moved Permanently");
    header("Location:$refering_page?s=$search_variables");
    exit;
?>
在我测试它的localhost上的

工作得很好。但是在实时服务器上它出错了:

Warning: Cannot modify header information - headers already sent by (output started at /home/sandrodz/public_html/devholidayge/wp-content/themes/sweetholiday/searchlogic.php:3) in /home/sandrodz/public_html/devholidayge/wp-content/themes/sweetholiday/searchlogic.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/sandrodz/public_html/devholidayge/wp-content/themes/sweetholiday/searchlogic.php:3) in /home/sandrodz/public_html/devholidayge/wp-content/themes/sweetholiday/searchlogic.php on line 16

15和16是退出前的行;

我按照答案中的建议尝试,但我得到同样的错误!

<?php
ob_start();

    //Search logic for Holiday.GE
    $search_variables = $_GET['s']. '+' .$_GET['cat'];
    $var_lang_now = $_GET['lang_current_search'];

        if ($var_lang_now == ru OR $var_lang_now == en) {
            $refering_page = 'http://dev.holiday.ge/' . $var_lang_now . "/";
        } else {
            $refering_page = 'http://dev.holiday.ge';
        }

    //This sends http post to url without curl
    header("Status: 301 Moved Permanently");
    header("Location:$refering_page?s=$search_variables");
    exit;

ob_end_flush();
?>

3 个答案:

答案 0 :(得分:1)

ob_start();放在开头,ob_end_flush();放在最后

答案 1 :(得分:0)

在脚本开头

使用它
ob_start();

并在此结束

ob_end_flush();

它将解决这个问题。前段时间我插入这些东西后面临同样的问题。

header("Location: $refering_page?s=$search_variables");
                 ^ //space should present.

答案 2 :(得分:0)

请在页面顶部使用此代码:

<?php ob_start(); ?>

及以下代码页面底部

<?php ob_flush(); ?>