• 技术文章 >后端开发 >php教程

    Laravel 5.4 session 生效问题

    PHP中文网PHP中文网2018-02-18 14:07:09原创1097
    在测试过程中发现 如果方法有echo 等函数输出到PHP的输出缓存中 存在 sessionID 不会放到http的请求头中 下次请求也就拿不到sessionid问题

    问题的原因

    代码位置:public/index.php

    $response->send();

    该方法代用方法 代码: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;
        }

    以前的原因出现在 headers_sent() 中

    有兴趣的同学可以测试一下 如果输出缓存存在数据 (在方法使用echo 之类的函数有打印行为) headers_sent() 函数则返回ture

    这样就解释了 在方法中存在打印的函数时候 你的session始终没有生效问题

    以上就是Laravel 5.4 session 生效问题的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:Laravel session 问题
    上一篇:session一直报错Session store not set on request 下一篇:Thinkphp5 使用composer中seeder播种机
    php培训_php实战培训【立即报名】-php中文网第20期

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• 分享一个有趣的php版本的扫雷!• php 资料上传类 • php中foreach循环有关问题 • PHP常用字符串处置函数 • 关于php与apache的配置有关问题
    1/1

    PHP中文网