Curious problem happening here on some scripts I coded a while back. We've upgraded our server from PHP 4.3.0 to 4.3.4 and now I'm getting those nasty "headers already sent errors." The problem is, I'm getting them BEFORE any apparent output (I understand how you can't send headers after writing anything to screen, but I'm not doing that).
I eliminated a few of the offending problems by re-sorting my code, but one of them is in a function that redirects the user using header("Location: ...") and it just won't work now. There's nothing in the change log that indicated any reason why this would be happening; any ideas? Maybe the php.ini got changed? I wouldn't even know where to look.
headers already sent on 4.3.4
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Hmm, but it did do the output first? Mine is simply stating:
Warning: Cannot modify header information - headers already sent by (output started at /web/sites/live/htdocs/snapshot/db_connect.inc:9) in /web/sites/live/htdocs/snapshot/db_actions.inc on line 433
For some reason the error always references db_connect.inc, which consists in its entirety of this:
So you see nothing could be output unless it died, and if that happened, shouldn't I see the output on screen ahead of the error?
Warning: Cannot modify header information - headers already sent by (output started at /web/sites/live/htdocs/snapshot/db_connect.inc:9) in /web/sites/live/htdocs/snapshot/db_actions.inc on line 433
For some reason the error always references db_connect.inc, which consists in its entirety of this:
Code: Select all
<?
$connection = mysql_pconnect($GLOBALS[Settings]->Database_Host,$GLOBALS[Settings]->Database_User,$GLOBALS[Settings]->Database_Password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($GLOBALS[Settings]->Database_Name, $connection)
or die("Couldn't select database. Has the admin set the user permissions properly for this database?" . mysql_error());
?>-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
On the one hand, I agree, it shouldn't be the problem.Unipus wrote:For some reason the error always references db_connect.inc, which consists in its entirety of this:
So you see nothing could be output unless it died, and if that happened, shouldn't I see the output on screen ahead of the error?Code: Select all
<? $connection = mysql_pconnect($GLOBALS[Settings]->Database_Host,$GLOBALS[Settings]->Database_User,$GLOBALS[Settings]->Database_Password) or die ("Couldn't connect to server."); $db = mysql_select_db($GLOBALS[Settings]->Database_Name, $connection) or die("Couldn't select database. Has the admin set the user permissions properly for this database?" . mysql_error()); ?>
But since that's where it wants to argue with you, I'd start there.
Should $GLOBALS[Settings] be in quotes? ["Settings"]?
If you're not seeing anything obvious, I'd comment out all the logic and see if the error goes away. Obviously you'll get a new error about databases not being connected and all that, but did the error about the headers go away?
If it does go away, then add the logic back a line at a time until the error returns.
Yes, in a way. If you use a certain layout of the page(s) the text itself might not be visible in the browser. Try looking at the page again, and "check source" on it.Unipus wrote:Hmm, but it did do the output first?
Cont. on TheBentinel.com's post; a smaller error (like the below notice) will pass and (often) work but the notice-error is still generated and "shown".
Code: Select all
Notice: Use of undefined constant foo - assumed 'foo' in /test/index.php on line 4
bar
<?php
// php source to get the above, and having your code in mind...
$foo['foo'] = 'bar';
echo $foo[foo];
?>