在测试过程中发现 如果方法有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 生效问题的详细内容。