How to fix invisible space problem in PHP?

As a result, functions of type session_startand setcookiecannot succeed, reporting:

Unable to change header information - headers have already been sent

But the target file looks like this:

1 <?php
2 session_start(); 

How to fix it?

castings

I found the problem, the files created by utf-8 become utf-8 + BOM after uploading to the server, so I temporarily solved the problem by saving it as utf-8 again.

BUT , there are many other files with the same problem, how can I solve the problem?

+3
source share
7 answers

, . Notepad ++, Emacs , . - <, .

+7

, ( ). . , Notepad ++ UTF-8 , ​​ ANSI.

+3

: ?> PHP - , .

+2

: ! -, -.

, .

+1

, ? , , ? >

  <?php
session_start();
session_register("count");
if(!isset($_SESSION))
{
    $_SESSION["count"]=0;
    echo "<p>counter initialized</p>\n";
}
else
{
    $_SESSION["count"]++;
}
echo "<p>The counter is now <b> $_SESSION[count]</b></p>";
echo "<p>Reload this page to increment</p>";
?>
0

, vi, .

, , , grep/xargs/sed, . , Windows.

, , ? > php tag... / , . php , , , , .

//

, , ? > . , .

0

PHP, php.ini .htaccess http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering

Then all of your output will be cached in the buffer until your script finishes and it is sent immediately. This is often good in terms of performance (since your server sends less, more, pieces of data). Depending on the architecture of your site, you can put flash (); after creating the HTML headers.

0
source

Source: https://habr.com/ru/post/1726069/


All Articles