Laravel 5.4.36 session 生效问题
2024-08-31 00:25:33
在测试过程中发现 如果方法有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始终没有生效问题
最新文章
- c#比较两个List相等
- Linux(ubanto):可以ping通IP,但不能ping通域名
- Electron-使用Electron开发第一个应用
- 孙鑫MFC学习笔记2:C++回顾
- .net社区
- rails利用big_sitemap生成sitemap
- Java使用代理Proxy访问网络及其验证
- 世界级Oracle专家Jonathan Lewis:我很为DBA们的未来担心(图灵访谈)
- [0.0]Analysis of Baidu search engine
- PERL 脚本
- ios实现截屏(转)
- 上次的AJAX定时刷新多ID不正确,这次请教了高手之后补全
- VC++学习之一
- html5移动开发--js温馨提示
- C#函数式程序设计之泛型(下)
- iwlist等工具的移植
- VS2015安装提示出现“安装包丢失或损坏”解决方法
- vi/vim下tab的长度修改
- ROS_Kinetic_20 ROS基础补充
- Mono.Cecil
热门文章
- nyoj 55 懒省事的小明(priority_queue优先队列)
- [luoguP1196] 银河英雄传说(并查集)
- [BZOJ2594] [Wc2006]水管局长数据加强版(LCT + kruskal + 离线)
- 通过JQUERY获取SELECT OPTION中选中的值
- 洛谷 P2853 [USACO06DEC]牛的野餐Cow Picnic
- 17、Java并发性和多线程-避免死锁
- java中普通的顶级类是不能使用static关键字修饰的。只有内部类可以使用static修饰,也可以不使用staitc关键字修饰。
- 从一个简单的例子谈谈package与import机制
- ubuntu 建立加密分區及其安全刪除
- 选择排序(2)——堆排序(heap sort)