Forum Moderators: coopster

Message Too Old, No Replies

$size = filesize($PHP_SELF);

         

davidpbrown

8:26 pm on Oct 16, 2003 (gmt 0)

10+ Year Member



Forgive a stupid question but I'm struggling to create Content-length: so it can be used in a HTTP/1.0 persistent connection which appears to be important in caching what is effectively a static page.

I have
$size = filesize($PHP_SELF);
header("Content-length: $size");
which is obviously incorrect.

I've seen something to the effect it needs an absolute filename rather than a URI but can't find how this is done, which surprised me as I would have expected this is used quite often.

dmorison

8:31 pm on Oct 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you have is wrong because content-length must refer to the length of the output of your script, not the length of the source code. Start here...

[uk.php.net...]

You need to:

1/ Turn output buffering ON at the top of your script with ob_start()

2/ ... rest of script ...

3/ use header("Content-length: ".ob_get_length()) at the end of your script.

davidpbrown

8:59 pm on Oct 16, 2003 (gmt 0)

10+ Year Member



Excellent hadn't even begun to go there.

Thanks for the quick response
:)