seblucas / cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
1.44k stars 229 forks source link

Removes "header()" to send as HTML #293

Closed lucanos closed 8 years ago

lucanos commented 8 years ago

This was causing a PHP error as the output body had already commenced at Line 1

seblucas commented 8 years ago

Can you share some informations, I cannot reproduce it on my end.

Thanks in advance

seblucas commented 8 years ago

@lucanos

ping ;)

lucanos commented 8 years ago

Rerun your test with error reporting switched on ("E_ALL"). Otherwise, the error is probably being produced, but muted, by your setup.

seblucas commented 8 years ago

Currently I'm running PHP7 with :

error_reporting = E_ALL | E_STRICT

and I have no errors (in the log or on the screen)

seblucas commented 8 years ago

Same with PHP 5.4.14 and PHP 5.6.24

seblucas commented 8 years ago

Do you have a closing ?> in your config_local.php ?

lucanos commented 8 years ago

Look at the file I made the change to.

Lines 1 & 2 are output to the browser - it's the HTML5 Doctype declaration, and the start of the HTML element.

You can't use the PHP header() command after you have started sending body content to the client. That is why it gave me an error. I have no idea why it isn't doing so for you, but it should be.

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

http://php.net/manual/en/function.header.php

seblucas commented 8 years ago

Let me rephrase, I know about this limitation and I know you're right and this PR will eventually be merged ;).

I'm just trying to understand why I don't have this problem to make sure it does not happen elsewhere / again

seblucas commented 8 years ago

Found it, I had this line in my php.ini :

output_buffering = 4096

Changing it to Off show the error you have.

seblucas commented 8 years ago

Thanks a lot.