猿问

无法修改标头信息-标头已由…WordPress问题发送

我遇到这个错误。而且我不知道如何处理。


无法修改标头信息-已发送的标头(输出始于/home/ben213/public_html/wp-includes/pluggable.php上的/home/ben213/public_html/wp-content/themes/Bendaggers/functions.php:9) 934行


我的Functions.php文件第9行是:


<?php if(function_exists('register_sidebar'))register_sidebar();?>

而我的pluggable.php#934是


function wp_redirect($location, $status = 302) {

    global $is_IIS;


    $location = apply_filters('wp_redirect', $location, $status);

    $status = apply_filters('wp_redirect_status', $status, $location);


    if ( !$location ) // allows the wp_redirect filter to cancel a redirect

        return false;


    $location = wp_sanitize_redirect($location);


    if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )

        status_header($status); // This causes problems on IIS and some FastCGI setups


    header("Location: $location", true, $status);}

endif;

因为我不是程序员,所以我很难解决这个问题。怎么了?请帮助我...


烙印99
浏览 608回答 2
2回答

守着一只汪

您的主题是将输出(文本)输出到浏览器,但是由于某种原因,WordPress会在呈现整个页面之前将用户(使用wp_redirect)重定向到该页面。您无法开始打印输出然后进行重定向,否则将看到错误。这就是Paul Grime在评论中所表达的。肯·怀特(Ken White)提到有类似问题的帖子。我已经通过缓冲脚本的输出来解决此问题。在主题functions.php文件中(每次加载主题页面时都会包含该文件)中,放置以下内容://allow redirection, even if my theme starts to send output to the browseradd_action('init', 'do_output_buffer');function do_output_buffer() {&nbsp; &nbsp; &nbsp; &nbsp; ob_start();}现在,即使您的主题的一部分开始向浏览器发送输入,PHP也不会在页面完全加载之前发送该文本,这使WordPress可以根据需要将用户重定向(作为其自身逻辑的一部分)。

慕雪6442864

如果您尝试从当前页面(具有条件或无条件)重定向到另一页面,请使用此代码。例如,您有两个页面A.php和B.php,当前您位于A.php,单击该按钮即可转到其他页面B.php。&nbsp; &nbsp;if(isset($_POST['save_btn']))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; //write some of your code here, if necessary&nbsp; &nbsp; &nbsp; &nbsp; echo'<script> window.location="B.php"; </script> ';&nbsp; &nbsp; &nbsp;}
随时随地看视频慕课网APP
我要回答