SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2003
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Solved] Headers already sent!?!

    Edit:
    Yeah, these are definately the problem lines (11,12)

    Code:
    	header("WWW-Authenticate: Basic entrer=\"Form2txt admin\"");
    	header("HTTP/1.0 401 Unauthorized");
    Anything wrong with those two?




    While using Andy Mack's 35mm slide gallery (here), I recieved the following error when accessing any of the password-protected scripts (delete.php; upload.php):

    Warning: Cannot modify header information - headers already sent by (output started at /*****/TripPhotos/config.php:21) in /*****/TripPhotos/delete.php on line 11

    Warning: Cannot modify header information - headers already sent by (output started at /*****/TripPhotos/config.php:21) in /*****/TripPhotos/delete.php on line 12
    Unauthorized access...
    (The absolute paths are edited.)


    I was able to locate the problem code (lines 11 and 12 in delete.php and upload.php, the error lines, are bolded). It is:
    if ( (!isset($PHP_AUTH_USER)) || ! (($PHP_AUTH_USER == $LOGIN) && ( $PHP_AUTH_PW == "$PASSWORD" )) ) {
    header("WWW-Authenticate: Basic entrer=\"Form2txt admin\"");
    header("HTTP/1.0 401 Unauthorized");
    error("Unauthorized access...");
    }
    Once that code was removed, the upload/delete scripts work fine.

    Please explain exactly what code to implement/remove, etc... I have no real knowledge of PHP and therefore need an answer explained in newbie language, please

    By the way... one of my files got chmodded to 000 somehow... not sure how. So I can't delete it using Cpanel's file editor. Any suggestions?

    Thanks in advance!
    Last edited by skyraider; Nov 24, 2004 at 19:03. Reason: solved

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem appears to be at /*****/TripPhotos/config.php:21, or line 21 of that file.

    You may have added some whitespace while editing that file.
    Lats...

  3. #3
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically something is being sent to the browser for output BEFORE those header functions are being called. You get the errors you're talking about when the headers have already been sent, usually by some previously sent content, and then you try to change the headers, which of course can't be changed because they were already sent. Whew!

    Is there anything that you added to the code that would be causing it to output something to the user before you try to change the headers?

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2003
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lats
    The problem appears to be at /*****/TripPhotos/config.php:21, or line 21 of that file.

    You may have added some whitespace while editing that file.
    whitespace? As in spacebar spaces, etc?

    Line 21 is:
    if ( (!isset($PHP_AUTH_USER)) || ! (($PHP_AUTH_USER == $LOGIN) && ( $PHP_AUTH_PW == "$PASSWORD" )) ) {
    header("WWW-Authenticate: Basic entrer=\"Form2txt admin\"");
    header("HTTP/1.0 401 Unauthorized");
    error("Unauthorized access...");
    }

    if ($_REQUEST['submitted2'])
    {
    umask (0);
    mkdir ("$abpath/$newdir", 0755);
    chmod ("$abpath/$newdir",0777);
    $file = fopen("$abpath/$newdir/album.txt","w");
    chmod ("$abpath/$newdir/album.txt",0777);
    fwrite($file,"$album");
    fclose($file);
    }

    if ($_REQUEST['submitted']){ // Begin processing portion of script
    Is there anything that you added to the code that would be causing it to output something to the user before you try to change the headers?
    No... nothing at all whatsoever. It is really strange that the directory "Nature's Vistas" (which changed to "Nature/'s Vistas") automatically, got chmodded to 000 somehow. Other than that, I can't think of anything that could have possibly caused the error. It did start occuring after that 000 chmod though.

    The 000 directory is weird - can't delete it via Cpanel's file manager.

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2003
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved!

    Putting ob_start(); on line 1 did the trick... got that suggestion from a user at another forum. No idea what it does, but no errors now


  6. #6
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skyraider
    whitespace? As in spacebar spaces, etc?

    Line 21 is:
    <snip>
    Looks like delete.php, what's around line 21 of config.php?
    Lats...


Bookmarks

Posting Permissions

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