PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
在测试过程中发现 如果方法有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始终没有生效问题
已抢7336个
抢已抢95474个
抢已抢14937个
抢已抢52725个
抢已抢195929个
抢已抢87512个
抢