Welcome Guest, Not a member yet? Register   Sign In
Cookie generating header too large error
#1

[eluser]carvingCode[/eluser]
I'm using cookies (CI's cookie class) to store $_POST data after a search which may be used to generate an exact same search at a later time (search data -> display chart/graph -> then give later option for downloading resulting dataset.)

Problem: I'm getting a header error (Bad Result - header too large) after a dozen or so test searches. Here are some specifics:

1) The cookie name is unique for each search - combination of session_id and current time (now()).

2) The test search writes 448 bytes to the cookie.

Based upon this, I am not sure why the error is being generated. I'm testing this in Firefox - haven't moved on to other browsers for this problem until I have a better grasp on what's happening.

Would appreciate a whack on the side of the head.

Randy
#2

[eluser]WanWizard[/eluser]
Depends on the webserver used, and it's configuration.

Apache by default has a maximum header length of 8Kb, IIS7 16Kb, II7.5 48Kb. For apache, you can modify the size in the confug using LimitRequestFieldsize.

However, I would advise you not to store this data in cookies (there is also a limit to the number of cookies stored per domain), but in the session record. Much more room, and no slow page transfer due to enormous headers...
#3

[eluser]carvingCode[/eluser]
Thanks, Wizard. I started out using sessions, then moved to cookies for some reason. Will move back as I agree this is best option.

Wonder if I was running into the max cookies per domain limit?
#4

[eluser]WanWizard[/eluser]
Possible. Depending on the browser the limit is 20 or 40.
#5

[eluser]carvingCode[/eluser]
Got it. Thanks.

Converted to sessions and works beautifully. Had to increase $config['sess_time_to_update'] so that the session wasn't regenerated too quickly. Running a couple tests on that now, but all should be fine.
#6

[eluser]carvingCode[/eluser]
Wizard (or others looking on),

Having an interesting problem with the conversion to sessions. All works fine if I open only one search results window. (This window has a chart and graph and a button to download the result's dataset.) The correct dataset is downloaded. The download is generated by an identical search based upon the session data I saved during the initial search.

But, if I leave that window open and perform another search (which opens a second window), the first search results window can't create and download it's dataset. The second search downloads fine.

It appears that the session data may be getting deleted, or I'm just not thinking about this correctly..

I'm writing a unique ID into the session date for each search.

Code:
/* Prep for writing to cookie - for file download. */
$id = now() . $this->session->userdata('session_id');

$cookie = array(
    'name' => $id,
    'url_title' => $url_title,
    'title' => $title,
    'years' => base64_encode(serialize($years)),
    'locations' => base64_encode(serialize($locations)),
    'option' => base64_encode(serialize($option)),
);

$this->session->set_userdata($cookie);

I am checking for this ID to then load from the session data the original $_POST vars to perform another search.

Code:
/* Last segment contains id of cookie (stored search params) */
$segment = $this->uri->segment($this->uri->total_segments());

if ($this->session->userdata('name') != $segment) {
    $continue = FALSE;
} else {
    /* Arrays serialized to store in cookie. */
    /* So unserialize to store back to array. */
    $url_title = $this->session->userdata('url_title');
    $title = $this->session->userdata('title');
    $years = unserialize(base64_decode($this->session->userdata('years')));
    $locations = unserialize(base64_decode($this->session->userdata('locations')));
    $option = unserialize(base64_decode($this->session->userdata('option')));
}

I'm sure the problem is either the way I'm creating the unique ID, or in the way I'm reading the values back from the session data.

Would appreciate feedback.

TIA

Randy




Theme © iAndrew 2016 - Forum software by © MyBB