Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php header error message

Posted on 2011-03-16
34
Medium Priority
?
347 Views
Last Modified: 2012-05-11
I get the following error message on my website,  it uses Apache, php and mysql.  Teh website pulls multiple pictures from the database.  

Do I need to compile PHP with some different paramaters to support pictures ? ??  or is this a standard coding error ???  php version 5.2 apache 2.2 mysql 5

I am only learning php.  

Warning: Cannot modify header information - headers already sent by
0
Comment
Question by:enigma1234567890
  • 14
  • 12
  • 4
  • +3
34 Comments
 

Author Comment

by:enigma1234567890
ID: 35145816
sorry this is the exach error Warning: Cannot modify header information - headers already sent by
0
 
LVL 12

Accepted Solution

by:
enachemc earned 624 total points
ID: 35145830
you cannot send any headers after you have written anything else on the page
for example, if your page starts with a space and then <?
0
 
LVL 11

Assisted Solution

by:NurAzije
NurAzije earned 156 total points
ID: 35145887
Get rid of the white space before and after <?php ?> tag, it works.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Assisted Solution

by:fabzster187
fabzster187 earned 156 total points
ID: 35145924
add the following to the page:

at the top of the page:
ob_start();

Open in new window


and at the bottom:
ob_flush();

Open in new window


that should sort u out
0
 

Author Comment

by:enigma1234567890
ID: 35145937
the cookie file is attached this is the file it complains about i think,  

What do yo mean remove white space after ?> can i have more lines of code in html code after the closing php tag if so they will have white spcaces ???
cookie.txt
0
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 624 total points
ID: 35145951
spaces at the end do not matter in respect to your problem
0
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 624 total points
ID: 35145964
if one of your setcookie lines is after another line that made PHP give a message(warning or error) it will fail
0
 

Author Comment

by:enigma1234567890
ID: 35146043
from the code if i rem out the second part of the code which stated is the cookie is empty then fill it in,  theis eliminates the error so how do i fix the code as i need to update the time on the cookie also
0
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 624 total points
ID: 35146066
eliminate setcookie lines, run the file and find out what your error or warning is
0
 
LVL 17

Assisted Solution

by:Shinesh Premrajan
Shinesh Premrajan earned 760 total points
ID: 35146081
Repalce

$rnd_id  = $HTTP_COOKIE_VARS["rnd_id"];

With this

$rnd_id  = $_COOKIE["rnd_id"];

Hope this helps

0
 

Author Comment

by:enigma1234567890
ID: 35146113
replacing the $HTTP_cookie didnt work ???
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35146153
Could you pls post the entire error msg that you are getting.

The code seems working fine for me
0
 

Author Comment

by:enigma1234567890
ID: 35146194
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/index.php:7) in /usr/local/apache2/htdocs/includes/newheader.txt on line 28


Note my fried tried the code on his server and it worked fine not sure why it works on other servers and not mine ???
Do i need to compile in some suport or something ????   I just did a basic php compile with
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-libdir=lib64
0
 

Author Comment

by:enigma1234567890
ID: 35146199
note line numbers are slightly different as i removed some small commments,  lime 28 is the line before the closing tag in php
0
 
LVL 17

Assisted Solution

by:Shinesh Premrajan
Shinesh Premrajan earned 760 total points
ID: 35146330
in the top of the script put these lines of code.

error_reporting(E_ALL);
ini_set("display_errors",1);

this will show up the actual error in the script.

Hope this helps
0
 

Author Comment

by:enigma1234567890
ID: 35146425
lines of code didnt report any more detail than what I had do they go to a log file some where ???
0
 
LVL 17

Assisted Solution

by:Shinesh Premrajan
Shinesh Premrajan earned 760 total points
ID: 35146458
aw that's frustrating.
In the newheader.txt file, there seems to be an extra enter character after the ?> closing tag. Make sure that you use a backspace untill you reach the > symbol and save the file.
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 304 total points
ID: 35146487
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/index.php:7) in /usr/local/apache2/htdocs/includes/newheader.txt on line 28

... says that you're outputting the newheader.txt inside the index.php code. Do you do include("includes/newgeader.txt") ? Do you "echo", "print" or output something there ?
0
 
LVL 17

Assisted Solution

by:Shinesh Premrajan
Shinesh Premrajan earned 760 total points
ID: 35146513
Right the problem is that newheader.txt should contain only the code defined in the

<?php .... ?> section.

If its like this the below one, thats the cause for the problem

<?php .... ?>
some web stuff was below here    <--- You cant write the contents below this line here, remove this/

since this will be outputted to the browser first and throwing you the err.
0
 

Author Comment

by:enigma1234567890
ID: 35147857
the only content deloc ?> is standard web code.  If i remove all of it I still have the issue so it has nothing to do with that.

The code is attached I dont cookie settings,  the problem is I think to do with the setcookie as I think it sends a header before the code has completed.  
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 304 total points
ID: 35148189
It does. What is your fiend's PHP version ?
0
 
LVL 17

Assisted Solution

by:Shinesh Premrajan
Shinesh Premrajan earned 760 total points
ID: 35148528
is standard web code.?

I think that is nothin to do with the error.

try this  in a new php file , you will get the same error message although this is also web standard.

if you want to avoid this then better remove the set cookie and add that to top of the script

=================== test.php

This is test

<?php

setcookie(.... ); //Set it to what ever variable

?>
0
 

Author Comment

by:enigma1234567890
ID: 35150208
friends version is also 5.2 might be a earlier release 5.2..5   mine is 5.2.17
His Apache is 1.3 mine is 2.2

Cant figure out why it works on that computer and not mine.  


When you say move set cookie to top of script I dont understand what is theissue with it ???
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35153898
OK if i am imaging it right, then the scenario here is
you have a setcookie function in the top of the page which is defined based on a condition then after that you are displaying the image from the database.
So the script is bascially displaying the image in that you are setting the cookie

Is the situation mentioned here rite?
0
 

Author Comment

by:enigma1234567890
ID: 35171201
its basically a cookie to keep track of the user.  If they have visited the site before we resite the counter back to 1 day is not we then setup a cookie.

thats basically it the html stuff doesnt matter as if I remove it i still get the error.  
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35179103
Could you attach your cookie script, which you have included in your script.
0
 

Author Comment

by:enigma1234567890
ID: 35179215
its in the 5th post
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35180001
Rt, so this is include file, to a main file. Please correct if its not the case.
0
 

Author Comment

by:enigma1234567890
ID: 35180033
this is the file to avoid confusion
code.txt
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35180456
Sorry wt is meant here is the code.txt is the include file that you are including in some another script.
so its another script how are you including that the issue seems
0
 

Author Comment

by:enigma1234567890
ID: 35197988
sorry lost what file are you talking about I dont have include file.  What line of code are you referencing in the code.txt ???
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35198137
i assume that you are including the code.txt, the one attached in the comment 35180033. Need to know in where in the main file you are including this.
0
 

Author Comment

by:enigma1234567890
ID: 35279296
I am lost dont understant what you need
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 35291424
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/index.php:7) in /usr/local/apache2/htdocs/includes/newheader.txt on line 28

this error message above means that you are including the newheader.txt file in the index.php page.

Right now in the index.php file, where are you including newheader.txt,  in the bottom,top of any code.

If there is any code above the include section then pls paste that code.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question