[Solved] Slide Gallery: Headers Already Sent?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skyraider
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2004 7:12 pm
Location: USA

[Solved] Slide Gallery: Headers Already Sent?

Post 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!
Last edited by skyraider on Wed Nov 24, 2004 8:03 pm, edited 1 time in total.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

skyraider
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2004 7:12 pm
Location: USA

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try putting ob_start(); on line 1
skyraider
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2004 7:12 pm
Location: USA

Post by skyraider »

Works nicely :) Thanks, Phenom!
Post Reply