sessions icon indicating copy to clipboard operation
sessions copied to clipboard

How do I get the sessionId

Open Guildhon opened this issue 4 years ago • 6 comments

I want get like this session_K36NW244LA2GB23N2HEYVWGTERU2S52C7YNV3Q2SDQLF53SQLJIQ

Guildhon avatar Aug 02 '19 11:08 Guildhon

it is hard to get the sessionId !!!

zhukovaskychina avatar Aug 07 '19 04:08 zhukovaskychina

Can't you just read it from the client's cookie ?

alkanna avatar Aug 17 '19 07:08 alkanna

You can only rewrite Session Strust by copy the old. copy all about the old and add func named SessionId().

type session struct { name string request *http.Request store sessions.Store session *sessions.Session written bool writer http.ResponseWriter } func (s *session) Session() *sessions.Session { if s.session == nil { var err error s.session, err = s.store.Get(s.request, s.name) if err != nil { log.Printf(errorFormat, err) } } return s.session } func (s *session) SessionId() string { return s.Session().ID }

doowsing avatar Nov 21 '19 13:11 doowsing

You can only rewrite Session Strust by copy the old. copy all about the old and add func named SessionId().

type session struct { name string request *http.Request store sessions.Store session *sessions.Session written bool writer http.ResponseWriter } func (s *session) Session() *sessions.Session { if s.session == nil { var err error s.session, err = s.store.Get(s.request, s.name) if err != nil { log.Printf(errorFormat, err) } } return s.session } func (s *session) SessionId() string { return s.Session().ID }

but session struct is private

ChinaHDJ1 avatar Jan 05 '20 06:01 ChinaHDJ1

I want to set my session id (switch session) as well

Anyway to implement this? Like the alternative of session_id($sess_id_1); in php?

wonson avatar Apr 07 '20 09:04 wonson

func (u *User) Test(c *gin.Context) {
	session := sessions.Default(c)
	session.Set("test", 123)

	of := reflect.ValueOf(session).Elem()
	realSession := of.FieldByName("session")
	sessionId := realSession.Elem().FieldByName("ID")
	//getid
	log.Println(sessionId.String())
       // setId
      	sessionPtr := reflect.NewAt(sessionId.Type(), unsafe.Pointer(sessionId.UnsafeAddr())).Elem()
	sessionPtr.SetString("this_is_test")

       // set cookie
        session.Save()
}

anynone avatar Nov 19 '20 06:11 anynone