Compress cookie data

Posted on 2005-03-01
Medium Priority
Last Modified: 2013-12-12
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
Question by:emu10k1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 13433840
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...

Author Comment

ID: 13454992
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

Accepted Solution

aib_42 earned 1500 total points
ID: 13466817
If you have the zlib extension to PHP, you could use the gzcompress() and the gzuncompress() functions to compress/uncompress any string.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question