Welcome! Log In Create A New Profile

Advanced

how to set query string based cookie value and expire time

Posted by sunbaoming 
how to set query string based cookie value and expire time
September 09, 2009 10:32AM
Hello,

I just migrated Apache to nginx, there is a rewrite rule to set cookie based on query string. If query string contains a parameter f=foo,then set Cookie (Key=f,Value=foo), and expire at two months later.

I use :

location / {

if($query_string ~ "([^&]*)f=([^&]*)"){ #check whether there has a 'f=xx' key/value pairs.
add_header Set-Cookie "f=$2; path=/; domain=bar.com";
}

it worked but how to set cookie expire time? It is a variable = $current_time + 60d


Best Regards.

baoming sun



Edited 1 time(s). Last edit at 09/09/2009 10:33AM by sunbaoming.
Re: how to set query string based cookie value and expire time
September 09, 2009 11:22AM
Have you tried using the UserID module? See http://wiki.nginx.org/NginxHttpUserIdModule. Maybe that can be adapted for your needs.

--
Jim Ohlstein
Re: how to set query string based cookie value and expire time
September 10, 2009 05:42AM
Jim:

I gave a try with UserID module , It set cookie with value something like 'wKhfOkqoyBuH7n5BAwMDAg=='. But what I wanted Cookie value is extracted from request query string.

for example:

when visit http://www.foo.com/index.html?f=google , a cookie need to set to browser :

Key = f
Value = google
expires = currenttime+60d

Baoming Sun
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready