[resolved] wp_redirect, WP2.5.1 and pluggable.php (1 post)

  1. evilzenscientist
    Posted 7 years ago #

    Kinda resolved - but needed a hack to pluggable.php

    Since upgrading to 2.5.1 from various versions I've had problems using wp_redirect and exec-php in pages. (I was evaluating the user ID and level to allow or disallow viewing pages; and redirecting on failure or success)

    I was getting the dreaded

    PHP Warning: Cannot modify header information - headers already sent by (output started at <foo>

    I threw up a clean dev box with 2.5.1 and reproduced it with no other plugins and the default theme.

    Eventually I tracked this down to a bug that was logged a while back; the fix isn't in 2.5.1

    Here's the bug: http://trac.wordpress.org/ticket/2860

    Here's my fix to wp-includes/pluggable.php - starting around line 690.

    /** remove header injection piece
    ** ref http://trac.wordpress.org/ticket/2860
    ** evilzenscientist - 28 May 2008
            if ( $is_IIS ) {
                    header("Refresh: 0;url=$location");
            } else {
                    if ( php_sapi_name() != 'cgi-fcgi' )
                            status_header($status); // This causes problems on IIS and some FastCGI setups
                    header("Location: $location");
    /** added new header injection and refresh
    ** http://trac.wordpress.org/ticket/2860
    ** evilzenscientist - 28 May 2008
            if( !headers_sent() ) {
                    if ($is_IIS)
                            header("Refresh: 0;url=$location");
                            header("Location: $location");
                    } else
                            echo "<meta http-equiv='refresh' content='0;url=$location' />";
    /** end of change */

    Usual disclaimers - may help someone else with similar issues; specifically with embedded php and wp_redirect.

Topic Closed

This topic has been closed to new replies.

About this Topic