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
emu10k1Asked:
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.
0
 
sjohnstone1234Commented:
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:

$_SESSION["some_value"]=5;
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):

<?php

session_start();

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

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

?>

Hope that's of use...
0
 
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
0
All Courses

From novice to tech pro — start learning today.