Compress cookie data

Hello experts. I have a site that needs to put much data in cookies, like 8000bytes but the Apache has the header field limitted to 8192. But I have to use cookies. There is a way to compress the cookies? If no, what you suggests to me? Thanks and its urgente
Who is Participating?
aib_42Connect With a Mentor Commented:
If you have the zlib extension to PHP, you could use the gzcompress() and the gzuncompress() functions to compress/uncompress any string.
You could compress the cookies but there is still a size limit to them (4Kb in some browsers). Depending on what you want to do, you could consider using PHP sessions?

Sessions are where a cookie is sent initially to the client containing a key such as fcc17f071bca9bf7f85ca281094390b4 - this can be used to retrieve data stored on the server-side, thus eliminating the need to send or receive large cookies with each request.

To use sessions in PHP you need to call session_start() at the beginning of your script, then store whatever data you need to maintain between requests in the $_SESSION array:

print $_SESSION["some_previously_stored_value"];

An example, which implements a separate counter for each client/browser that accesses the page (refresh to increase the count):



if(!isset($_SESSION["count"]) || !is_int($_SESSION["count"])) {
} else {

print "You have accessed this page ".$_SESSION["count"]." times<br />";


Hope that's of use...
emu10k1Author Commented:
I was using Session but i had to use cookies forced.. i got solve this problem using post vars with hidden fields... because post vars can have large amount of data.. thanks
All Courses

From novice to tech pro — start learning today.