Project

General

Profile

Setting custom cookie directly from Lighttpd

Added by j99 about 13 years ago

Hello,

We are using Lighttpd 1.4.19 on Debian Lenny 64-bit. Currently our web application uses the following PHP script just to generate a custom cookie for user and then redirect him to the other URL. The script looks like this:

header("Set-Cookie: userID=" + md5($_SERVER["REMOTE_ADDR"]) +";");
header("Location: http://www.same-server.com/other-website/");
?>

That's it - cookie is generated based on MD5 hash of user's IP address and then user is redirected to some other address... This is some kind of security feature and it works great exactly as we want it to work EXCEPT this script gets just too much traffic and PHP gets overloaded all the time. Since the script is really simple we thought that something like this could also be configured directly in Lighttpd without using the PHP script. We managed to configure this in lighttpd.conf file:

$HTTP["url"] =~ "^/our-script.php" {
setenv.add-response-header = ( "Set-Cookie" => "userID=XXXXXX;" )
url.redirect = ( ".*" => "http://www.same-server.com/other-website/" )
}

this works except we don't know how to calculate "XXXXXX" part with a custom string like in PHP script above (md5 hash of user's IP address).. Is it possible? How? Any suggestion is appreciated because this could really take the load off our PHP backend.

thank you, regards.


Replies (1)

RE: Setting custom cookie directly from Lighttpd - Added by nitrox about 13 years ago

Lua to the rescue! See mod_magnet and absoLUAtion.

    (1-1/1)