dongyan1548 2017-12-31 21:34
浏览 46
已采纳

回声没有清除会话

I am using Echo for my web application. I tried to implement Login and Logout. When I tried to logout, its not clearing the session. Here is my code:

func Logout(c echo.Context) error {
    sess, _ := session.Get("session", c)
    sess.Options = &sessions.Options{
        Path:     "/",
        MaxAge:   -1,
        HttpOnly: true,
    }
    sess.Values["username"] = ""
    sess.Values["authenticated"] = ""
    sess.Save(c.Request(), c.Response())
    return c.Redirect(http.StatusSeeOther, "/")
}

After logout I checked the session values, its not changing or clearing anything. I am using these packages for session management:

"github.com/labstack/echo-contrib/session"
"github.com/gorilla/sessions"
  • 写回答

1条回答 默认 最新

  • dongyan1899 2018-01-02 19:39
    关注

    The problem is in the client side . Browsers are ignoring Set-Cookie in redirect response when domain of the cookie is localhost. So I have to use 127.0.0.1 instead of localhost.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部