今日头条 焦点资讯 营销之道 企业报道 淘宝运营 网站建设 软件开发 400电话
  当前位置: 首页 » 资讯 » 软件开发 » 正文

Laravel 5.4 session 生效问题

放大字体  缩小字体 发布日期:2018-02-20  来源:企业800网  作者:新格网  浏览次数:576  【去百度看看】
在测试过程中发现 如果方法有echo 等函数输出到PHP的输出缓存中 存在 sessionID 不会放到http的请求头中 下次请求也就拿不到sessionid问题

问题的原因

代码位置:public/index.php

$response->send();

该方法代用方法 代码:vendor/symfony/http-foundation/Response.php

    
    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中文网其它相关文章!

 
关键词: Laravel,session,问题
 
[ 资讯搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 
0条 [查看全部]  相关评论

 
网站首页 | 关于我们 | 联系方式 | 使用协议 | 版权隐私 | 网站地图 | 排名推广 | 广告服务 | 积分换礼 | 网站留言 | RSS订阅 | 吉ICP备11001726号-6
企业800网 · 提供技术支持