bungle / lua-resty-session

Session library for OpenResty – flexible and secure
BSD 2-Clause "Simplified" License
320 stars 111 forks source link

how to open session by session id? #54

Closed hashwing closed 6 years ago

hashwing commented 6 years ago

How to open session by session id? For example, I want to destroy session by session id.

bungle commented 6 years ago

If you are using cookie storage, you really cannot do that. If you are using Server Side storage, e.g. redis, then you can just remove key sessions:<id> (the prefix can be changed though).

hashwing commented 6 years ago

Thanks! I do it :


local sid = ngx.var.arg_sid
local session = require "resty.session".new({ storage = "shm" })
local s = session.start()
if sid ~= nil then
    s.storage:destroy(ngx.decode_base64(sid))
else
    s:destroy()
end