PDA

View Full Version : "Headers already sent" error, not the normal case!


ConfusedOfLife
05-05-2003, 09:34 PM
Hi

I'm trying to send some headers to stop the page from being cached, but I get this usual error: "Headers are already sent"!

Hey, I'm not sending my headers in the middle of the page, there is NO space before these commands, and I'm putting them exactly above my document, only after the php starting tag! Here it's my code:


<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>


Don't bother yourself, it's nothing wrong with the code! I copied that exactly from the php manuals, the only thing that might be the cause of my problem (I think!) is that I'm trying to use it in the "index.php" file, the file that is loaded automatically by the server when the address is entered. I say it because I wrote the same thing for other pages and I didn't have any problem.

If I'm missing anything in here, I really appriciate it if you point it out!

bijan

Spookster
05-05-2003, 09:42 PM
I would double check for spaces. Make sure you don't have any spaces before <?php. All it takes is one space which will be sent to the browser. Also you are not using any prepend features are you or your host for that matter?

ConfusedOfLife
05-05-2003, 09:56 PM
Originally posted by Spookster
I would double check for spaces. Make sure you don't have any spaces before <?php. All it takes is one space which will be sent to the browser. Also you are not using any prepend features are you or your host for that matter?

Well, I'm using this at the top of my index page:

<?PHP
include("dup.inc");
include("utils.inc");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

.
.
.


And here it's the whole content of dup.inc that I included above:

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>

<?PHP
$USERNAME = "";
$PASSWORD = "";
$DBNAME = "titleContextCMS";


?>


I also do not know what a prepend feature is! but as the name implies, I don't think it's prepending anything, because I don't have the same problem with other pages, or maybe they're just doing it on "index" pages? Who knows, I should ask them if I don't get any other answer!

Spookster
05-05-2003, 10:17 PM
There is nothing wrong with your code. That error is caused by sending output to the browser which the server sends headers with it and then trying to manually send headers afterwards.


What's in this file?

include("utils.inc");

You are trying to send any headers or using creating sessions or anything like that in there are you?

ConfusedOfLife
05-06-2003, 01:40 PM
NO NO! It's nothing important in it. It's just a big class that I put in that file and I'm using it in the other pages. Just a big class without any header, session or whatever! Thanks for your attention, I have to call the admins I think!