Project

General

Profile

[Solved] Acquiring current time() to set in cookie

Added by thatseattleguy almost 2 years ago

using standard Lighty 1.4.55 as provided under RedHat (RHEL) 8.x
(so not current 1.4.60+ versions)

I'm able to perform a Set-Cookie just fine in my .lua file:

lighty.header["Set-Cookie"] = "xxxip=" .. lighty.env["request.remote-ip"] .. "; SameSite=Lax" 

But now I want to change the cookie to be the current time (the time the page is served) instead of the remote IP address. Not working. :( I've tried things like this:

lighty.header["Set-Cookie"] = "xxxip=" .. lighty.env["set_time"]() .. "; SameSite=Lax" 
and
lighty.header["Set-Cookie"] = "xxxip=" .. lighty.env["set_time()"] .. "; SameSite=Lax" 

...but I don't even get past the parsing stage before it throws a 500 error with these.

Can someone point me in the right direction? The "before 1.4.60 / after 1.4.60" thing in the current docs is very confusing, as I'm never sure what applies to my case or not under 1.4.55. Thanks!!!


Replies (2)

RE: Acquiring current time() to set in cookie - Added by gstrauss almost 2 years ago

The "before 1.4.60 / after 1.4.60" thing in the current docs is very confusing, as I'm never sure what applies to my case or not under 1.4.55. Thanks!!!

How is that confusing? You're using lighttpd 1.4.55. That is "before 1.4.60". "1.4.60 and later" does not apply to 1.4.55.

...but I don't even get past the parsing stage before it throws a 500 error with these.

look in the lighttpd error log.

Are you making up syntax? If "set_time" is set in the environment
lighty.header["Set-Cookie"] = "xxxip=" .. lighty.req_env["set_time"] .. "; SameSite=Lax"

If you want to ask lua for the current time, look up the lua os.time() (In lighttpd 1.4.60 and later, lighty.c.time() is faster than os.time())

RE: Acquiring current time() to set in cookie - Added by thatseattleguy almost 2 years ago

Thanks! No, wasn't making up syntaxes completely blindly - "set_time" was a typo in my question, but I unfortunately we can't edit after posting. :{ Anyways, your answer was extremely helpful!

I now have this:

ourtime = os.time()
lighty.header["Set-Cookie"] = "xxxip=".. ourtime .. "; SameSite=Lax" 

...and it works perfectly. I'll update to lighty.c.time() when RedHat moves to 1.4.60 or above.

Thanks so much for the quick reply, and thanks of course for lighty!

    (1-2/2)