1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

please help me in fixing Cannot modify header information error!

Discussion in 'PHP' started by c4gamerz, Jul 28, 2010.

  1. #1
    Hi,

    I am trying to code options page for a new wordpress theme. I followed following tutorial to code this page

    http://blog.themeforest.net/wordpress/create-an-options-page-for-your-wordpress-theme

    now the problem is i am getting

    Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\themes\crunchtech\functions.php:195) in C:\xampplite\htdocs\wordpress\wp-content\themes\crunchtech\functions.php  on line 47
    Code (markup):
    here is the code

    function mytheme_add_admin() {
    
        global $themename, $shortname, $options;
    
        if ( $_GET['page'] == basename(__FILE__) ) {
        
            if ( 'save' == $_REQUEST['action'] ) {
    
                    foreach ($options as $value) {
                        update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
                    foreach ($options as $value) {
                        if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
                    [B][COLOR="Red"]header("Location: themes.php?page=functions.php&saved=true");[/COLOR][/B]
                    die;
    
            } else if( 'reset' == $_REQUEST['action'] ) {
    
                foreach ($options as $value) {
                    delete_option( $value['id'] ); }
    
                [COLOR="Red"][B]header("Location: themes.php?page=functions.php&reset=true");[/B][/COLOR]
                die;
    
            }
        }
    
        add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
    
    }
    Code (markup):
    i have colored conflicting lines. Please help me in fixing this issue.
    Thanks in advance.
    SEMrush
     
    c4gamerz, Jul 28, 2010 IP
    SEMrush
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    The line you need to look at is:

    C:\xampplite\htdocs\wordpress\wp-content\themes\crunchtech\functions.php on line 47
     
    ThePHPMaster, Jul 28, 2010 IP
  3. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Just except some CSS formatting problem, I can see no PHP error on the linked page. Anyway, you need to check line 195 not 47. I believe either some output is printed on this line, or cookie is set. Suppose you're printing from your php file using print, echo or die function, or you're setting a cookie. It means, the server already started sending http response to the client. On the way, you cannot modify the http header and redirect the user to different page. This is how a web server and a PHP scripts works.
     
    techbongo, Jul 28, 2010 IP
    c4gamerz likes this.
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    Just to confirm it's line 195 that the problem occurred on and not 47
     
    themullet, Jul 28, 2010 IP
  5. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #5
    You need to add this at the beginning of your PHP script:
    ob_start( );
    PHP:
    And this at the end of your PHP script:
    ob_end_flush( );
    PHP:
     
    Rainulf, Jul 28, 2010 IP
    c4gamerz likes this.
  6. c4gamerz

    c4gamerz Well-Known Member

    Messages:
    294
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #6
    finally figured out the problem. It was basically xampp which was causing this problem as when i uploaded files to web server code was executing fine without throwing any errors.
    Thanks to all those who tried to help me :)
     
    c4gamerz, Jul 29, 2010 IP
  7. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #7
    Never use XAMPP. I believe, some people here will protest my idea. But still I have to say, XAMPP is the worst Apache based web server I've ever used. Instead try Apache2Triad. It's not featureful, but it's perfect. I never became able to run hello_world.php file even, on this server.
     
    techbongo, Jul 29, 2010 IP