1

I have strange problem in every PHP page, at end of every response there is some special character, that is not related to PHP script, I test it with just <?php phpinfo();?> page that is there.

They are like this �

But that is not in 404 static page response, I think that is related to php config over version or, not Apache config, but I can’t find what cause this.

Bad situation is that it cause every AJAX/Json response fails, because change structure of response data by adding special character at end of every response

What cause this problem and how can solve it?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
hosein
  • 519
  • 5
  • 25
  • 2
    It could be the UTF-8 BOM settings on your files. – Giacomo1968 Jun 12 '14 at 02:37
  • so , i should remove bom from php.ini file? – hosein Jun 12 '14 at 02:38
  • possible duplicate of [PHP: json\_encode() SyntaxError if use of include\_once()](http://stackoverflow.com/questions/22897923/php-json-encode-syntaxerror-if-use-of-include-once) – potashin Jun 12 '14 at 02:39
  • @hosein Look at my answer. This is most likely due to the difference between line endings on the files you have—and where they came from—versus the server they are on now. BOM just means “Byte Order Map” which is a whole other thing. – Giacomo1968 Jun 12 '14 at 03:04
  • i used this command wget --header="accept-encoding: gzip" http://onesite.com and see : ^_�^H^@^@^@^@^@^@^C^C^@^@^@^@^@^@^@^@^@ at end of every response – hosein Jun 12 '14 at 07:22
  • @hosein Then the only solution would be to disable mod_gzip and mod_deflate. What OS is your server on? – Giacomo1968 Jun 12 '14 at 08:05
  • Debian wheezy 7.5, but i need it because OJS(http://pkp.sfu.ca/ojs/) don't work correctly without it – hosein Jun 12 '14 at 12:52
  • @hosein Can you please post the output of `curl -I` (which sends back headers) to your question? – Giacomo1968 Jun 12 '14 at 14:35
  • HTTP/1.1 200 OK Date: Sat, 14 Jun 2014 06:16:02 GMT Server: Apache/2.2.22 (Debian) Accept-Ranges: bytes X-Powered-By: PHP/5.4.4-14+deb7u9 Expires: Sun, 19 Nov 1978 05:00:00 GMT Last-Modified: Sat, 14 Jun 2014 06:16:02 +0000 Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0 ETag: "1402726562" Content-Language: en X-Generator: Drupal 7 (http://drupal.org) Vary: Accept-Encoding Content-Type: text/html; charset=utf-8 – hosein Jun 14 '14 at 02:46

1 Answers1

1

According to this answer on Server Fault, the issue is problems with mod_gzip:

The problem is being caused by mod_gzip and the fact that you do not have a final newline in your files. The newline problem is caused by serving Windows-encoded files on a Unix system.

This might be connected to line ending differences between Windows & Unix machines. I actually answered a similar question earlier today. Specifically:

Different operating systems use different characters to mark the end of line:

  • Unix / Linux / OS X uses LF (line feed, '\n', 0x0A)
  • Macs prior to OS X use CR (carriage return, '\r', 0x0D)
  • Windows / DOS uses CR+LF (carriage return followed by line feed, '\r\n', 0x0D0A)

If you are on a Linux server you can install the dos2unix tool to convert the PHP files in question to properly formatted Linux text files.

If you are on Ubuntu—for example—just run this command to install it:

sudo apt-get install dos2unix

Then you can run it like this on a file:

dos2unix some_kind_of_file.php

Which would take some_kind_of_file.php and convert it in place from Windows line endings to Unix line endings. More details here.

Community
  • 1
  • 1
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • JakeGould, that is in all page , i used this command : find . -type f -exec dos2unix {} {} \; to convert all files to unix format but this don't work – hosein Jun 12 '14 at 04:53
  • i used this command wget --header="accept-encoding: gzip" http://onesite.com and see : ^_�^H^@^@^@^@^@^@^C^C^@^@^@^@^@^@^@^@^@ at end of every response – hosein Jun 12 '14 at 07:19