Link to home
Start Free TrialLog in
Avatar of emu10k1
emu10k1

asked on

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
Avatar of sjohnstone1234
sjohnstone1234
Flag of United Kingdom of Great Britain and Northern Ireland image

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...
Avatar of emu10k1
emu10k1

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of aib_42
aib_42

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial