Duplicate set-cookie: ci-session fields in header using codeigniter

For every time $ this-> session-> set_userdata () or $ this-> session-> set_flashdata () is used in my controller, another identical "Set-Cookie: ci_session = ..." http sent by the server is added .

Multiple Set-Cookie fields with the same cookie name in the http header are not suitable according to rfc6265.

So, is there a way to use codeigniter sessions without creating multiple identical "set-cookies:" s?

(I used curl to check the HTTP header)

+6
source share
3 answers

check https://github.com/EllisLab/CodeIgniter/pull/1780

By default, when using a cookie session handler (encrypted or unencrypted), the CI sends the entire Set-Cookie header each time a new value is written to the session. This causes several clicks to be sent to the client.

This is a problem because if too many values ​​are written to the session, the HTTP headers can grow quite large and some web servers will reject the response. (see http://wiki.nginx.org/HttpProxyModule#proxy_buffer_size )

The solution should only run 'sess_save ()' once immediately after sending all the other headers before displaying the contents of the page.

+5
source

I believe that you can pass the array to $this->session->set_userdata(); I have not tested this code, so just try something in the following lines:

 $data = array( 'whatever' => 'somevalue', 'youget' => 'theidea' ); $this->session->set_userdata($data); 

NB: When I say that I have not tested the code. I used this code and I know that it works, I mean that I did not test it if it reduces the number of headers sent.

0
source

In my case, the error is in the browser (Chrome). It stores 2 cookies and sends them to the server, which makes the server create a new session all the time. I fixed it by clearing the cookies in the browser. Hope this helps someone. :)

0
source

Source: https://habr.com/ru/post/913625/


All Articles