0

I am doing a simple project, and I want to have a login session. There is a good example here: http://webpython.codepoint.net/cgi_session_class but I can not understand, how do I check if the session is already established?

1 Answer 1

1

That class takes care of handling new sessions entirely transparently.

The only way you can detect if a session is new is by storing something in the session and test for that:

if not 'seen' in session.data:
    # new session, set a flag
    session.data['seen'] = True

because a new session is always empty, but only if you set values will returning sessions not be empty.

Sign up to request clarification or add additional context in comments.

9 Comments

Thank you, that's what I guessed. Do you know, why do I get "message = "'Session' object has no attribute 'data'"" error?
@Anarion: you need to create an instance of the Session class, only instances have the data attribute: session = Session(...).
That's how I'm using it: sess = session.Session(expires=365*24*60*60, cookie_path='/') and I get an eroor inside of the class, on thins line: elif isinstance(expires, int): => 51 self.data['cookie']['expires'] = expires
MAy be this line didn't work? self.data = shelve.open(session_dir + '/sess_' + sid, writeback=True)
Are you sending the Set-Cookie header at all? Do read and understand the sample code in that page first.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.