user1547766
user1547766

Reputation: 475

Storing Long Array in Cookie

I know the method of storing the data in php. But this method doesn't work when I am storing a long array in PHP. That array has about 3000 values (82382 characters).

I am doing this:

$encoded_db_data = base64_encode(serialize($query_result));
setcookie("db_select_result", '$encoded_db_data');

but db_select_result is printing blank (no value). How can i solve this problem?

Upvotes: 1

Views: 121

Answers (1)

Ofir Baruch
Ofir Baruch

Reputation: 10356

A user agent MAY ignore a received cookie in its entirety. For example, the user agent might wish to block receiving cookies from "third-party" responses or the user agent might not wish to store cookies that exceed some size.

From: http://www.faqs.org/rfcs/rfc6265.html

Consider the next options:

1.Split the array's data and put it in more than one cookie.

2.Use sessions (Unlike cookies they have "short-life") [http://www.php.net/manual/en/session.examples.basic.php]

3.Store that data in a Database with a "unique key" , then set a cookie with that unique key so you'll be able to identify which data to pull from the database.

4.Use less data from your array and try to put it in a cookie.

Upvotes: 1

Related Questions