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.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Cannot modify header information

    Hey,
    I'm working on a big PHP/MYSQL image upload service and I got the upload part up and running. There's just one problem in my download.php script when I try and download the images from the database these errors show up:

    Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php:7) in E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php on line 23
    Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php:7) in E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php on line 24
    Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php:7) in E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php on line 25

    Now here's my PHP:
    PHP Code:
    if(isset($_GET['id'])) 
    {
    $con mysql_connect("localhost","****","****");
    mysql_select_db("wh"$con); 
    $id    $_GET['id'];
    $query "SELECT productMainimage_size, productMainimage_type, productMainimage " .
             
    "FROM products WHERE productMainimage_name = '$id'";
    $name $row['productMainimage_name'];
    $type $row['productMainimage_type'];
    $size $row['productMainimage_size'];
    $content $row['productMainimage'];         

    $result mysql_query($query) or die('Error, query failed' .trigger_error(mysql_error()));
    list(
    $name$type$size$content) = mysql_fetch_array($result);
    header("Content-length: $size");
    header("Content-type: $type");
    header("Content-Disposition: attachment; filename=$name");
    echo 
    $content;

    mysql_close($con);
    exit;

    Hope one of you guys can help with this frustrating problem.

  • #2
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    It's pretty much telling you what the problem is - and several times at that. It even gives you the line number:

    download.php:7

    You have already written some output at line 7 of download php, so your attempts to write certain headers is nonsensical.

    Without seeing the rest of the script, it's impossible to say what is going on, but here is the best advice I can give... start at LINE 7 of download.php
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yeah I figured that one out already only thing is that the <?php
    tag is on line 7.

  • #4
    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 lamasu View Post
    Yeah I figured that one out already only thing is that the <?php
    tag is on line 7.
    You have HTML content before that line, hence the output.

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Oh and here's the rest of the script:
    Code:
    <html>
    <head>
    <title>Download File</title>
    </head>
    <body>
    PHP Code:
    <?php
    if(isset($_GET['id'])) 
    {
    $con mysql_connect("localhost","****","****");
    mysql_select_db("wh"$con); 
    $id    $_GET['id'];
    $query "SELECT productMainimage_size, productMainimage_type, productMainimage " .
             
    "FROM products WHERE productMainimage_name = '$id'";
    $name $row['productMainimage_name'];
    $type $row['productMainimage_type'];
    $size $row['productMainimage_size'];
    $content $row['productMainimage'];         

    $result mysql_query($query) or die('Error, query failed' .trigger_error(mysql_error()));
    list(
    $name$type$size$content) = mysql_fetch_array($result);
    header("Content-length: $size");
    header("Content-type: $type");
    header("Content-Disposition: attachment; filename=$name");
    echo 
    $content;

    mysql_close($con);
    exit;
    }
    ?>
    Code:
    </body>
    </html>

  • #6
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You get the same result with or without the HTML.

  • #7
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    Yes, that write, you have written content with:

    Code:
    <html>
    <head>
    <title>Download File</title>
    </head>
    <body>
    It's too late to send headers after this :-) Send them before, and check you are calling the latest version of the script (your browser/server is not caching)

    Also worth mentioning that script is vulnerable to SQL injection attacks. If I manipulate the querystring so it unfolds to:

    Code:
    0; drop table products;#
    or worse
    Code:
    0; drop database wh;#
    You may see the issue.
    Last edited by 120; 12-18-2010 at 08:08 PM.
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I gave it a try yet with no result although the error message changed to:

    Warning: Header may not contain more than a single header, new line detected. in E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php on line 16

    And line 16 contains:

    PHP Code:
    header("Content-length: $size"); 

  • #9
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by lamasu View Post
    I gave it a try yet with no result although the error message changed to:

    Warning: Header may not contain more than a single header, new line detected. in E:\xampp\htdocs\Comet10\wh\whPMS2\inc\scripts\download.php on line 16

    And line 16 contains:

    PHP Code:
    header("Content-length: $size"); 
    OK. So what do you think: "Header may not contain more than a single header" may mean? TRY THIS LINK.

    Personally I would have a look at the output off of the server with something like LIVE HTTP HEADERS and see what it's spitting out.
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by 120 View Post
    Personally I would have a look at the output off of the server with something like LIVE HTTP HEADERS and see what it's spitting out.
    I would venture a guess that it's the $size variable in the header() call that the error points to. $size has a newline in it, and you can't set headers with newlines.


  •  

    Tags for this Thread

    Posting Permissions

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