PDA

View Full Version : any thoughts on this error?



pkcidstudio
07-11-2006, 09:34 PM
here is the function the error says this is wrong


function NoCache() {
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
}

then i call this later


NoCache();

here is the include file it is asking about. check linked file
thankx for the help

Twey
07-11-2006, 10:05 PM
here is the function the error says this is wrongWhat error? I see no error.

pkcidstudio
07-12-2006, 01:40 PM
currently there is no error showing becasue i have commented it out.
does anything look bad in the way that function is written?

Twey
07-12-2006, 01:53 PM
Not obviously so, no. Why don't you post the error so we can see what the problem is?

pkcidstudio
07-12-2006, 02:10 PM
Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/j/l/ejlcustomgolf/html/eventCalendar.php:8) in /home/content/e/j/l/ejlcustomgolf/html/_admin/includes.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/j/l/ejlcustomgolf/html/eventCalendar.php:8) in /home/content/e/j/l/ejlcustomgolf/html/_admin/includes.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/j/l/ejlcustomgolf/html/eventCalendar.php:8) in /home/content/e/j/l/ejlcustomgolf/html/_admin/includes.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/j/l/ejlcustomgolf/html/eventCalendar.php:8) in /home/content/e/j/l/ejlcustomgolf/html/_admin/includes.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/j/l/ejlcustomgolf/html/eventCalendar.php:8) in /home/content/e/j/l/ejlcustomgolf/html/_admin/includes.php on line 18

posted-

Twey
07-12-2006, 02:30 PM
As I suspected.
There's nothing wrong with the function; the problem is that you're calling it after HTML has already been sent to the browser. header (http://www.php.net/header)() can only be called before any other output is sent to the browser.

pkcidstudio
07-12-2006, 02:34 PM
so i need to move it where?
thankx twey for the help

Twey
07-12-2006, 02:41 PM
Simplest place is right at the beginning of the page, and make sure there is nothing before the opening <?php tag; that includes whitespace.

pkcidstudio
07-12-2006, 02:42 PM
Great, Twey thankx for your continued help in the forums.

ice
08-03-2006, 09:03 AM
Or you just start your PHP Script with this:

<?php
ob_start();
and end it with this:

ob_end_flush();
?>

blm126
08-03-2006, 01:58 PM
Or you just start your PHP Script with this:

<?php
ob_start();
and end it with this:

ob_end_flush();
?>
You don't want to do that unless you have to. It will slow down the script.

mwinter
08-03-2006, 02:55 PM
[Using output buffering] You don't want to do that unless you have to. It will slow down the script.I would disagree with that statement for three reasons (though it's not necessarily an exhaustive list):


By buffering data, the preprocessor can send data to the server in large segments, rather than piecemeal.
Output buffering allows filters to be applied that might not otherwise be possible. An obvious example is compression. Though it's not necessary to compress output, the benefits typically outweigh any possible performance penalty.
Output buffering provides the opportunity for the script to determine the content length and set the corresponding Content-Length header. Without this header, the connection must be closed in order to signal the end of the entity. Any further requests must establish another connection, rather than using persistent connections defined by HTTP/1.1.

If anything, the use of output buffering should be common practice, not something to avoid. In fact, output buffering is enabled by default in the recommended configuration to accumulate writes into 4kB chunks.

Mike

Twey
08-03-2006, 08:46 PM
In the case of using it to avoid having to correctly place header() calls, however, it could lead to difficult-to-read code, so I would not recommend using it for expressly this purpose.

mwinter
08-03-2006, 09:40 PM
In the case of using it to avoid having to correctly place header() calls, however, it could lead to difficult-to-read code, so I would not recommend using it for expressly this purpose.Surely that's an issue of code design though, not output buffering itself. Of course, if simple language constructs permit the correct and timely sending of HTTP headers then there's no point of explicitly introducing buffering, but the same can be said in any instance where something is used without any tangible benefits.

Mike

Twey
08-03-2006, 10:00 PM
Indeed so. That's what I was trying to point out: that abusing output buffers in this way would likely lead to poor code design.

blm126
08-03-2006, 11:53 PM
Ok,I'm confused.I thought output buffering would slow things down because I read this in the php.ini filer.

; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit. You can enable output buffering during runtime by calling the output
; buffering functions.

but early it says this

; - output_buffering = 4096 [Performance]
; Set a 4KB output buffer. Enabling output buffering typically results in less
; writes, and sometimes less packets sent on the wire, which can often lead to
; better performance. The gain this directive actually yields greatly depends
; on which Web server you're working with, and what kind of scripts you're using.

So is output buffering faster or slower? :confused:

Twey
08-04-2006, 12:22 AM
In 90% of cases, faster. Read mwinter's post.