Laravel 5.4.36 session effective, laravel5.4.36

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.