Laravel 5.4.36 session effective, laravel5.4.36
During the test, it is found that if the method has functions such as echo output to the PHP output cache, sessionID will not be placed in the http request header, and sessionid will not be available in the next request.
Cause
Code Location: public/index. php
$response->send();
Code of the alternative method: vendor/symfony/http-foundation/Response. php
/** * Sends HTTP headers. * * @return $this */ public function sendHeaders() { // headers have already been sent by the developer if (headers_sent()) { return $this; } // headers foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) { foreach ($values as $value) { header($name.': '.$value, false, $this->statusCode); } } // status header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode); // cookies foreach ($this->headers->getCookies() as $cookie) { if ($cookie->isRaw()) { setrawcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } else { setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } } return $this; }
Previous causes appear in headers_sent ()
If you are interested, you can test the headers_sent () function if there is data in the output cache (A printing behavior occurs in functions such as echo in the method) and the true function is returned.
This explains that your session never takes effect when the printed function exists in the method.