php - CodeIgniter session set-cookie duplicated -- how to solve -


update:

I wonder if anyone can review my answer and Can you see if any hole in it

A well documented issue is when using codingers and sessions:

A set in the Summary coding - Cookies each time set_userdata Is called.

I got a partial solution:

The only problem with this solution is that the code needs to be inserted everywhere to clean all the headers An easy way? I have modified the code a bit to remove php errors, but is there any way I can use hooks or something?

  & lt; Php class extends MY_Controller CI_Controller {public function __construct () {origin: __construct (); } // View (Modified) http://ha17.com/1745-bigip-f5-header-max-size-collides-with-codeigniters-bizarre-session-class/ Protected Function _removeDuplicateCookieHeaders () {// Clean All cookies are set ... $ headers = headers_list (); $ cookies_to_output = array (); $ Header_session_cookie = ''; $ Session_cookie_name = $ this- & gt; Config- & gt; Item ('sess_cookie_name'); Forex currency ($ header as $ header) {list ($ header_type, $ data) = explosion (':', $ header, 2); $ Header_type = trim ($ header_type); $ Data = trim ($ data); If (stroller ($ header_type) == 'set-cookie') {header_remove ('set-cookie'); $ Cookie_value = current (Explode (';', $ data)); List ($ key, $ val) = explosion ('=', $ cookie_value); $ Key = trim ($ key); If ($ key == $ session_cookie_name) {// overwrite (yes, do so!) $ Header_session_cookie = $ data; to continue; } Else {//} is not a cookie related to the session, add it as usual, a CSRF or some other cookie which we might get from $ cookies_to_output $] ARAR ('header_type' = & gt; $ header_type, 'data' = & gt; $ Data) are set; }}} If (empty ($ header_session_cookie)) {$ cookies_to_output [] = array ('header_type' = & gt; 'set-cookie', 'data' = & gt; $ header_session_cookie); } Foreign currency ($ cookies_to_output $ cookie) {header ("{$ cookie ['header_type']}: {$ cookie ['data']}", false); }}}}  

Edit: If you're using $ $ then just use this code- & gt; Load-> (See). If you are using the correct echo in a controller, then it can remove the output before removing the header.

Editing requires PHP 5.3 or newer.

I have found a way that I feel that I help others with this issue. I have not tested it completely yet, but it seems to work.

Application / hook / session_cookie_fixer.php

  & lt ;? Php class sessioncookiefixer {// View (modified from) http://ha17.com/1745-bigip-f5-header-max-size-collides-with-codeigniters-bizarre-session-class/ Removing function toolbar session () { $ CI = & amp; Get_instance (); // All cookies are set which are clear ... $ headers = headers_list (); $ Cookies_to_output = array (); $ Header_session_cookie = ''; $ Session_cookie_name = $ CI- & gt; Config- & gt; Item ('sess_cookie_name'); Forex Currency ($ header as $ header) {list ($ header_type, $ data) = explosion (':', $ header, 2); $ Header_type = trim ($ header_type); $ Data = trim ($ data); If (stroller ($ header_type) == 'set-cookie') {header_remove ('set-cookie'); $ Cookie_value = current (Explode (';', $ data)); List ($ key, $ val) = explosion ('=', $ cookie_value); $ Key = trim ($ key); If ($ key == $ session_cookie_name) {// overwrite (yes, do so!) $ Header_session_cookie = $ data; to continue; } else {// not a cookie related to the session, add it as usual, a CSRF or some other cookie which we might get from $ cookies_to_output $] ARAR ('header_type' = & gt; $ header_type, 'data' = & gt; $ Data) are set; }}} If (! $ Header_session_cookie) = $ cookies_to_output [] = array ('header_type' = & gt; 'set-cookie', 'data' = & gt; $ header_session_cookie); } Foreign currency ($ cookies_to_output $ cookie) {header ("{$ cookie ['header_type']}: {$ cookie ['data']}", incorrect); }}}? & Gt; Array ('class' = & gt; 'sessioncookiefixer')   

application / config / hooks.php

  $ hook ['post_controller'] [] = array ('class' => , 'Function' = & gt; 'deleted duplicate session cookie header', 'filename' = & gt; 'session_cookie_fixer.php', 'filepath' = & gt; hook ',' parameters' = & gt; array ));    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -