I
I
impressive172014-11-10 18:10:38
PHP
impressive17, 2014-11-10 18:10:38

What does this error mean in PHP?

What does this error mean:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at K:\home\newsite.loc\www\index.php:1) in K :\home\newsite.loc\www\index.php on line 2.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
# artur #, 2014-11-10
@passshift

session_start() should be done at the very beginning of the php file (roughly speaking). Or you are trying to restart the session (let's say in the header)

S
Sergey, 2014-11-10
Protko @Fesor

session_start creates a session. What does it mean? This means that it creates a place where infa will be saved (the default file) and assigns some random identifier to this place. So that the session is not lost, the user must send it with each request. It so happened that this case is resolved through cookies.
Cookies are set with a Set-Cookie header, so when you call the session_start function it is the same as sending the header to the user.
In general, HTTP requests/responses have two parts - headers and body. Headers describe the parameters of the request/response, in particular, what exactly is contained in the body of the request/response and, in the case of a request, what the user/client wants to receive.
We think further. To work with response headers, SAPI in PHP provides you with the header. Let's simplify life for ourselves and imagine that session_start pulls it inside. Everything that comes out through other places in stdout (through echo or print for example, or just some character before <? PHP got stuck) is considered the body of the response. Since the sequence of actions must be followed when generating an HTTP response, you cannot change headers as soon as at least something, even one byte, has entered the output buffer.
Partially this problem is solved by the output buffer management functions. That is, we can tell the puff to wait a little, and then flush the buffer. Then you can safely swap echo and header in the code.
Here... In addition to non-observance of the order of interaction with headers and the output of information, there is often such a thing as the headers of the source codes themselves (UTF BOM). Any normal editor can remove them.
It is also recommended not to close the <?php tag, since after the closed tag an extra line break may be added and this will play a cruel joke with inclusions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question