UPDATE:
我想知道是否有人可以查看我的答案并看看其中是否有任何漏洞。
使用 codeigniter 和会话时存在一个有据可查的问题:
codeigniter 标头中重复的“set-cookie: ci-session”字段 https://stackoverflow.com/questions/10228548/duplicated-set-cookie-ci-session-fields-in-header-by-codeigniter/13763598#13763598
总之,每次调用 set_userdata 时,codeigniter 都会执行一个 set-cookie。
我在以下位置找到了部分解决方案:
http://ha17.com/1745-bigip-f5-header-max-size-collides-with-codeigniters-bizarre-session-class/ http://ha17.com/1745-bigip-f5-header-max-size-collides-with-codeigniters-bizarre-session-class/
该解决方案的唯一问题是需要在各处插入代码。有没有一种简单的方法来清除所有标题?我对代码进行了一些修改以消除 php 错误,但是有没有办法可以使用钩子或其他东西?
<?php
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent:: __construct();
}
//See (modified from) http://ha17.com/1745-bigip-f5-header-max-size-collides-with-codeigniters-bizarre-session-class/
protected function _removeDuplicateCookieHeaders ()
{
// clean up all the cookies that are set...
$headers = headers_list();
$cookies_to_output = array ();
$header_session_cookie = '';
$session_cookie_name = $this->config->item('sess_cookie_name');
foreach ($headers as $header)
{
list ($header_type, $data) = explode (':', $header, 2);
$header_type = trim ($header_type);
$data = trim ($data);
if (strtolower ($header_type) == 'set-cookie')
{
header_remove ('Set-Cookie');
$cookie_value = current(explode (';', $data));
list ($key, $val) = explode ('=', $cookie_value);
$key = trim ($key);
if ($key == $session_cookie_name)
{
// OVERWRITE IT (yes! do it!)
$header_session_cookie = $data;
continue;
}
else
{
// Not a session related cookie, add it as normal. Might be a CSRF or some other cookie we are setting
$cookies_to_output[] = array ('header_type' => $header_type, 'data' => $data);
}
}
}
if ( ! empty ($header_session_cookie))
{
$cookies_to_output[] = array ('header_type' => 'Set-Cookie', 'data' => $header_session_cookie);
}
foreach ($cookies_to_output as $cookie)
{
header ("{$cookie['header_type']}: {$cookie['data']}", false);
}
}
}