how to compress a cookie value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

how to compress a cookie value

Post by jasongr »

Hello

I need to store some very long text inside a cookie using php's setcookie
the problem is that sometimes the text is too long for the browser to handle

and I get the following error:
400 Bad Request

Your browser sent a request that this server could not understand.
Size of a request header field exceeds server limit.

Is there a way to compress the value I am about to save in the cookie
and then to uncompress it again when I read the value from the cookie?

I just need to make sure that the encoding of the compressed value will be
legal for the browser to store in the cookie so that the uncompression will work

Is this possibe?
I would appreciate leads to PHP compression solutions if possible

regards
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I have to ask.. what are you storing in the cookie?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if this will be used on multiple servers, you'll still have a problem with size limitations of cookies. There are several alternates, such as storing it in session variables or a database.

gzcompress() may be of interest, it has links to other compressions php supports.
Post Reply