You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Mark Sweiger <ms...@cisco.com> on 2002/08/09 23:12:59 UTC

Setting the value of persistent cookies in a multi-server environment

Hello everyone,

We have several servers running Apache 1.3.20 under Unix.  We would like to 
create persistent cookies for users of these servers and we want the value 
of the cookie to be unique across all servers.  mod_usertrack does this 
with the following code:

gettimeofday(&tv, &tz);

ap_snprintf(cookiebuf, sizeof(cookiebuf), "%s.%d%ld%d", rname, (int) getpid(),
                 (long) tv.tv_sec, (int) tv.tv_usec / 1000);

Essentially, the cookie gets set to the concatenated string:

remote_host_ip_address.pid | seconds_since_1970 | (microseconds/1000)

For example, the generated cookie could look like this:

Apache=152.32.60.132.284731028850470160

While I can see that the mod_usertrack cookie value algorithm pretty much 
guarantees that cookie values will be unique for all users across a 
distributed set of servers, the resultant cookie is a very long string, 
which makes for a corresponding relational database cookie key that doesn't 
index or match very quickly using SQL.

My question is this:  Has anybody figured out a better algorithm for a 
unique cookie value *across multiple Apache servers* that results in a 
shorter string, preferably one that could be stored as a 4 or 8 byte number 
in a database?

Thanks,
Mark