Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

php header error message

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
enigma1234567890
Asked:
enigma1234567890
  • 14
  • 12
  • 4
  • +3
13 Solutions
 
enigma1234567890Author Commented:
sorry this is the exach error Warning: Cannot modify header information - headers already sent by
0
 
enachemcCommented:
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
 
NurAzijeCommented:
Get rid of the white space before and after <?php ?> tag, it works.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
fabzster187Commented:
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
 
enigma1234567890Author Commented:
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
 
enachemcCommented:
spaces at the end do not matter in respect to your problem
0
 
enachemcCommented:
if one of your setcookie lines is after another line that made PHP give a message(warning or error) it will fail
0
 
enigma1234567890Author Commented:
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
 
enachemcCommented:
eliminate setcookie lines, run the file and find out what your error or warning is
0
 
Shinesh PremrajanEngineering ManagerCommented:
Repalce

$rnd_id  = $HTTP_COOKIE_VARS["rnd_id"];

With this

$rnd_id  = $_COOKIE["rnd_id"];

Hope this helps

0
 
enigma1234567890Author Commented:
replacing the $HTTP_cookie didnt work ???
0
 
Shinesh PremrajanEngineering ManagerCommented:
Could you pls post the entire error msg that you are getting.

The code seems working fine for me
0
 
enigma1234567890Author Commented:
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
 
enigma1234567890Author Commented:
note line numbers are slightly different as i removed some small commments,  lime 28 is the line before the closing tag in php
0
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
enigma1234567890Author Commented:
lines of code didnt report any more detail than what I had do they go to a log file some where ???
0
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
Lukasz ChmielewskiCommented:
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
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
enigma1234567890Author Commented:
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
 
Lukasz ChmielewskiCommented:
It does. What is your fiend's PHP version ?
0
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
enigma1234567890Author Commented:
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
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
enigma1234567890Author Commented:
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
 
Shinesh PremrajanEngineering ManagerCommented:
Could you attach your cookie script, which you have included in your script.
0
 
enigma1234567890Author Commented:
its in the 5th post
0
 
Shinesh PremrajanEngineering ManagerCommented:
Rt, so this is include file, to a main file. Please correct if its not the case.
0
 
enigma1234567890Author Commented:
this is the file to avoid confusion
code.txt
0
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
enigma1234567890Author Commented:
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
 
Shinesh PremrajanEngineering ManagerCommented:
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
 
enigma1234567890Author Commented:
I am lost dont understant what you need
0
 
Shinesh PremrajanEngineering ManagerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 14
  • 12
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now