Forums

how to create diff sessions for diff user in bottlepy app?

In my project http://meet1995.pthonanywhere.com i have created a login sys but i have a problem that when i login from on pc and at same time when my friend logs in ,if i logout of my account the my friend acc is also logged out please help I am a beginner i came to know that its smthing related to sessions please help

Do you have any session management currently? Bottle doesn't include any out of the box, but there are middleware solutions available. For example, see this recipe.

If you're not familiar with web app session management, essentially the first time you see a client visit your site you create a unique random identifier for them and set it in a cookie in your response. You also create a record in a local file or database (on PA a database is probably a better option). Whenever they make a new request, you read the cookie and use the identifier it to look up their session information in the database. Once you've got a session you can store whatever information you need in it. Typically, frameworks and middleware platforms offer this as a nicely packaged solution which automatically sets and retrieves the cookie without you having to worry about it, and I recommend using one of those, at least at first.

There are various security issues related to session management which you may wish to look into, but I wouldn't worry about those at all until you've got a basic solution working.

+1 to what Cartroo says. The important thing is to store the "who is logged in" information on something associated with the a cookie-managed session rather than in a variable in your app, as those variables will be the same for everyone.

All this talk of cookies has made me hungry!

~a2j

You guys tend to relate programming languages to food and drink (like cookies, pie and coffee). That shouldn't impair the main function of this forum, namely talking about issues from the PythonAnywhere users themselves. Being hungry is a little bit off-topic.

@ronan -- the forum has to two functions, it's partially for users to help each other out, and partially to build a community. part of that last may well involve talking about cookies I'm afraid.

Here's an attempt to make sure the balance is right though -- @meet1995, you've got two options. first is to learn all about cookies and session management, which I would definitely recommend, being all very edumecational. The second option is to just use a package that magically does it all for you and "just works". If you're struggling with bottle, I'd recommend Django...