Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Header Problem?

  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts

    Header Problem?

    Hello I'm getting this error:
    Warning: Cannot modify header information - headers already sent by (output started at blahblah/pages.php:5) in blahblah/comments.php on line 14

    I can't figure out what's going wrong.
    This is what I have in pages.php: (I put up to line 14, line 5 is the "<style ..." line)
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    >
    <
    html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <
    head>
    <
    style type="text/css">

    body{
    background#C6D0F7;
    margin0 auto;
    font-familyverdana;
    height100%;
    font-size11px;
    }


    .... 

    And this is my comments.php page:
    PHP Code:
    <?php
    include ('secure.php');
    $comment no_injection($_POST['comment']);
    $id intval($_GET['id']);
    if(isset(
    $_COOKIE["username"])){
    $userid=$_COOKIE['userid'];
    $sql mysql_query("SELECT * FROM users WHERE id='$userid'");
    while(
    $row mysql_fetch_array($sql)){
    $url 'index.php?pages=profile&id='.$id.'&messages=done#commentmessage';
    if (
    $row['password'] == $_COOKIE['code']) {
    mysql_query("INSERT INTO comments (user, comment, profileid) VALUES ('$userid', '$comment', '$id')") or die (mysql_error());
    header("Location: $site_url/$url");
    }}}
    ?>

    Appreciate any help
    Thanks
    Last edited by wincode; 11-21-2010 at 12:09 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You have to issue any headers before you send any page output to the client.

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    838
    Thanks
    172
    Thanked 90 Times in 90 Posts
    Hi

    headers already sent by

    open file pages.php:5
    Remove these 3  from yr page just before <?php at top


    you will need to use an HEX editor to see them

    I use this free one
    http://mh-nexus.de/en/hxd/

    save (without bom signature)

    LT

  • Users who have thanked low tech for this post:

    wincode (11-21-2010)

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Or maybe?

    }}}
    header("Location: ".$site_url."/".$url);
    exit();
    ?>

  • Users who have thanked DrDOS for this post:

    wincode (11-21-2010)

  • #5
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    @MattF: how do I issue the header if I have a template? The comments.php is an include in pages.php

    @Low_Tech: I checked the file with the Hex editor, but I couldn't find  in them

    @DrDos: I tried that, and it's not working.

    Thanks a lot for your time

  • #6
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post
    if you use : Notepad ++
    change page Encoding to UTF-8 Without BOM.

    try this solution.

  • Users who have thanked aimads for this post:

    wincode (11-21-2010)

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Post the complete pages.php file.

  • #8
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    @Aimads: I changed it to UTF-8 Without BOM, saved it, but I still had the same problem. When I closed and reopened the page, it was back to Ansi.

    I've uploaded the file to here.

    Thank you

  • #9
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    That download is an executable and nobody is going to download it. Post the contents of the page here please (using the proper PHP tags).
    Dave .... HostMonster for all of your hosting needs

  • #10
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Oh I'm sorry. Here's the content:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <style type="text/css">

    body{
    background: #C6D0F7;
    margin: 0 auto;
    font-family: verdana;
    height: 100%;
    font-size: 11px;
    }

    html{height: 100%;}

    #headerz{
    min-width: 1000px;
    width: 100%;
    background: #bb2448;
    height: 100px;
    }
    #top{width: 1000px;
    margin: 0 auto;
    }
    #topleft{
    width: 200px;
    float: left;}

    #topright{
    width: 300px;
    float: right;
    padding-top: 5px;}


    #bars
    {
    min-width: 1000px;
    width: 100%;
    background: #333;
    height: 35px;
    }




    /* THE BODY*/

    #main{
    width: 1000px;
    margin: 0 auto;
    background: #eee;
    border-left: #333 solid 1px;
    border-right: #333 solid 1px;
    overflow: auto;
    }

    #bodyleft{
    width: 200px;
    float: left;
    background: #eeeeee;
    height: 100%;
    }
    #bodymid{
    width: 650px;
    float: left;
    background: #eeeeee;
    height: 100%;
    }
    #bodyright{
    width: 150px;
    float: right;
    background: #eeeeee;
    height: 100%;
    padding-top: 5px;
    }


    #foot
    {
    min-width: 1000px;
    margin: 0 auto;
    width: 100%;
    background: #444;
    height: 35px;
    color: #ccc;
    }

    #footpadder{
    line-height: 35px;
    width: 1000px;
    margin: 0 auto;
    }




    /* THE MENU*/
    #bar
    {
    list-style: none;
    margin: 0;
    }

    #topbar
    {
    width: 1000px;
    margin: 0 auto;
    }

    #bar li
    {
    list-style: none;
    background: #333;
    float: left;
    line-height: 35px;
    }
    #bar a
    {
    color: #ccc;
    text-decoration: none;
    height: 35px;
    padding: 0 25px;
    display: block;
    }
    #bar a:hover
    {
    color: #fff;
    background: #355999;
    text-decoration: none;
    }


    /*The Roundbox*/
    .spiffy{display:block}
    .spiffy *{
      display:block;
      height:1px;
      overflow:hidden;
      font-size:.01em;
      background:#eeeeee;
      }
    .spiffy1{
      margin-left:3px;
      margin-right:3px;
      padding-left:1px;
      padding-right:1px;
      border-left:1px solid #da6666;
      border-right:1px solid #da6666;
     }
    .spiffy2{
      margin-left:1px;
      margin-right:1px;
      padding-right:1px;
      padding-left:1px;
      border-left:1px solid #cf1717;
      border-right:1px solid #cf1717;
      background:#e7c0c0;}
    .spiffy3{
      margin-left:1px;
      margin-right:1px;
      border-left:1px solid #e7c0c0;
      border-right:1px solid #e7c0c0;}
    .spiffy4{
      border-left:1px solid #da6666;
      border-right:1px solid #da6666}
    .spiffy5{
      border-left:1px solid #e5b2b2;
      border-right:1px solid #e5b2b2;}
    .spiffyfg{
      background:#eeeeee;
      text-align: right;
      padding-right: 5px;
      padding-left: 5px;
      height: 80px;}

      
      
      
    #loginboxleft{
    width: 80px;
    height: 80px;
    float: left;
    }

    #loginboxright{
    width: 100%-80px;
    height; 80px;
    float: right}
      
      

      
    #comment{width: 400px; margin: 0 auto; overflow: auto;}
    #comment2wrap{float: left; width: 100%;}
    #comment2{padding-left: 5px; margin-left: 60px; min-width: 200px; min-height: 70px;}
    #comment1{float: left; width: 60px; margin-left: -100%;}
    #commenttitle{ font-weight: bold;}

    #commentadded{margin: 0 auto; height: 25px; text-align: center; color: #eee; width: 300px; border: 1px solid #008000; background: #239953;}







    #twocolmain{width: 750px; margin: 0 auto;min-height: 35px;border-top: 1px #355999 solid;background: #ffffff;}
    #twocolmain2{width: 750px; margin: 0 auto;min-height: 35px; max-height:35px;border-top: 1px #355999 solid;background: #eaf2d3;}
    #twocolwrap{float: left;width: 100%;}
    #twocol2{margin-left: 20%; width: 80%; padding-left: 5px; padding-top: 5px;}
    #twocol1{float: left;width: 20%; margin-left: -100%; padding-top: 5px}


    #profilecol{width: 100%; margin: 0 auto; margin-top: -5px;}
    #profilecol2wrap{float: left; width:100%;}
    #profilecol2{margin-left: 200px;  width: 575; padding-left: 5px; padding-top: 5px;}
    #profilecol1{float: left; margin-left: -100%; width: 200px; padding-top: 5px;}


    #subcol{width: 100%; margin: 0 auto; overflow: auto;}
    #subcol2wrap{float: left; width: 100%}
    #subcol2{margin-left: 50%; width: 50%-5px; padding-left: 5px; }
    #subcol1{float: left; margin-left: -100%; width: 50%; }


    #halfcol{width: 100%; margin: 0 auto;}
    #halfcol2wrap{float: left; width: 100%}
    #halfcol2{margin-left: 50%; width: 25%; padding-left: 5px; background: #ffcfcf;}
    #halfcol1{float: left; width: 25%; margin-left: -75%; padding-right: 5px;  background: #ffcfcf; text-align: right; font-weight: bold;}

    #half2col{width: 100%; margin: 0 auto;}
    #half2col2wrap{float: left; width: 100%}
    #half2col2{margin-left: 50%; width: 25%; padding-left: 5px; background: #dfebf1;}
    #half2col1{float: left; width: 25%; margin-left: -75%; padding-right: 5px;  background: #dfebf1; text-align: right; font-weight: bold;}



    #profileheader{width: 100%; height: 25px; margin: 0 auto;background: #dfebf1; border-top: 1px solid #355999;}
    #profilehtext{width: 100%-5px; padding-left: 5px; padding-top: 5px; font-weight: bold;}

    #profileque{padding-left: 5px;width: 100%-5px; text-align: left; font-weight: bold; color: #aaa;}
    #profileans{padding-left: 10px;}

    #profilec{width: 100%; background: #ff0000; overflow: auto;}
    #profilec1{width: 70px; background: #ffff00; float: left;}
    #profilec2{width: 200px; padding-left: 5px; background: #00ff00; float: left;}
    #profilec3{width: 15px; padding-left: 5px; background: #00ffff; float: left;}
    #profilec4{width: 160px; padding-left: 5px; background: #0000ff; float: left;} 
    #profilec5{width: 160px; padding-left: 5px; background: #ff00ff; float: left;} 
      

    #padder{
    padding: 5px;}
    </style>
    </head>


    <body>
    <div id="headerz">
        <div id="top">
            <div id="topleft">
            <img src="logo.png" />
            </div>
            <div id="topright">
                        <div>
                  <b class="spiffy">
                  <b class="spiffy1"><b></b></b>
                  <b class="spiffy2"><b></b></b>
                  <b class="spiffy3"></b>
                  <b class="spiffy4"></b>
                  <b class="spiffy5"></b></b>

                  <div class="spiffyfg">
                            
                    <?
            
    if(isset($_COOKIE['username']))
            {        
            
    $uid=$_COOKIE['userid'];
            echo
    '<div id="loginboxleft">';
            
    $profileboximg=mysql_query("SELECT * FROM users where id='$uid'") or die($mysql_error);
            
    $profileboximg2=mysql_fetch_array($profileboximg);
            echo
    '<img src="'.$site_url.'/avatars/thumbs/thumb_'.$profileboximg2['profilepicture'].'" height="80px">
            </div>
            <div id="loginboxright">'
    ;
            
    $uid=$_COOKIE['userid'];
            echo
    $_COOKIE['username'].'<br/>
            <a href="index.php?pages=profile&id='
    .$uid.'">My Profile</a><br/><a href="login.php?action=logout">Logout</a>';
            echo
    '</div>';
            }
            else{
            echo
    '
            <form action="login.php" method="POST">
            Email: <input type="text" name="email"><br/>
            Password: <input type="password" name="password"><br/>
            <input type="submit" name="submit" value="Login">
            or <a href="index.php?pages=register">Register</a>
            </form>'
    ;
            }
            
    ?>
                
                  </div>

                  <b class="spiffy">
                  <b class="spiffy5"></b>
                  <b class="spiffy4"></b>
                  <b class="spiffy3"></b>
                  <b class="spiffy2"><b></b></b>
                  <b class="spiffy1"><b></b></b></b>
                </div>

                

            </div>
            
        </div>
    </div>

    <div id="bars">
        <div id="topbar">
            <ul id="bar">
            <li><a href="index.php">Home</a></li>
            <li><a href="index.php?pages=profiles">Profiles</a></li>
            <li><a href="index.php?pages=videos">Videos</a></li>
            <li><a href="index.php?pages=rankings">Rankings</a></li>
            </ul>
        </div>
    </div>


    <div id="main">
    <div id="bodyleft">
    Left Column<br/>
    </div>
        <div id="bodymid"><div id="padder">
        <?php include('content.php'); ?>
        </div></div>
        <div id="bodyright">
        Right column<br/>
    </div>
    </div>

    <div id="foot"><div id="footpadder">
    Footer
    </div>
    </div>

    </body>

    </html>

  • #11
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by djm0219 View Post
    That download is an executable and nobody is going to download it. Post the contents of the page here please (using the proper PHP tags).
    The actual link to the uploaded file is way down at the bottom of the box and hard to see. The big download button is not it! Sneaky people.

  • #12
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,285
    Thanks
    4
    Thanked 201 Times in 198 Posts
    Quote Originally Posted by DrDOS View Post
    The actual link to the uploaded file is way down at the bottom of the box and hard to see. The big download button is not it! Sneaky people.
    Ah, sneaky indeed.
    Dave .... HostMonster for all of your hosting needs

  • #13
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    The only way you're going to sort it with that script is to use output buffering, unless you practically rewrite the thing. Change the top of the script to:

    Code:
    <?php
    
    ob_start();
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    and at the very end of the script put:

    Code:
    <?php
    
    $output = ob_get_contents();
    ob_end_clean();
    exit($output);
    
    ?>
    It's actually a poorly designed script, but you have the easy option, (hack), above or the hard option to sort it. Put an exit() call after the header call in that other script too, as DrDos suggested earlier.

  • Users who have thanked MattF for this post:

    wincode (11-21-2010)

  • #14
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Matt F: The two codes you provided did the job.
    But the other way is to sort it out? How would I go about that?

    Thanks a lot for all your help

  • #15
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by wincode View Post
    But the other way is to sort it out? How would I go about that?
    I wouldn't worry about it, to be honest. There's nothing wrong with output buffering per se, (I use it myself so that I can do any output alterations necessary and such). It's just a bit more hacky in your case because of the fact that the script isn't exactly written logically, (hence why the problem exists), but it will do no harm whatsoever to leave as is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •