开发者

Storing a session using cookies or http session variables for a scalable solution?

开发者 https://www.devze.com 2023-02-14 05:28 出处:网络
I have one web app which under the login process stores the userId in a 开发者_如何学JAVAhttp session variable(After confirmation of course!). I\'m not using any session variables other than this one

I have one web app which under the login process stores the userId in a 开发者_如何学JAVAhttp session variable(After confirmation of course!). I'm not using any session variables other than this one to retrieve information about the user. I don't know if this one is the most scalable solution for me yet. Do my server reserve any memory for this? Is it better to use cookies instead?


If you are using multiple application servers (now or in the future), I believe the http session variable is dependent to the server the user is on (correct me if I'm wrong), so in this case, you can find a "sticky session" solution that locks the user to a particular server (e.g. EC2's Load Balancers offer this: http://aws.amazon.com/about-aws/whats-new/2010/04/08/support-for-session-stickiness-in-elastic-load-balancing/ ).

I recommend using a cookie (assuming my logic above is right), but you should make sure you have some sort of security measure on that so users can't change their cookie and gain access to another user's account. For example, you could hash some string w/ a secret key and the user ID which you check server-side to confirm it has not been tampered with.

0

精彩评论

暂无评论...
验证码 换一张
取 消