Page 1 of 1

[Solved] Slide Gallery: Headers Already Sent?

Posted: Wed Nov 24, 2004 7:18 pm
by skyraider
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!

Posted: Wed Nov 24, 2004 7:39 pm
by rehfeld

Posted: Wed Nov 24, 2004 7:45 pm
by skyraider
Yes, but what's that mean for my script?

Code: Select all

<?php

require('config.php');

function error ($error_message) &#123;
	echo $error_message."<BR>";
	exit;
&#125;

if ( (!isset($PHP_AUTH_USER)) || ! (($PHP_AUTH_USER == $LOGIN) && ( $PHP_AUTH_PW == "$PASSWORD" )) ) &#123;
	header("WWW-Authenticate: Basic entrer="Form2txt admin"");
	header("HTTP/1.0 401 Unauthorized");
	error("Unauthorized access...");
&#125;


if ($_REQUEST&#1111;'submitted2'])
&#123;
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);
&#125;
There's the top bit of the code from upload.php. I don't understand how I can rewrite the code to not send out that error as described in the article.

Posted: Wed Nov 24, 2004 7:58 pm
by John Cartwright
try putting ob_start(); on line 1

Posted: Wed Nov 24, 2004 8:02 pm
by skyraider
Works nicely :) Thanks, Phenom!