问题的原因
代码位置: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始终没有生效问题
| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |