0

For the business-logic reason, I need to set a sessionid cookie for the each site visitor, even if there are no actual data stored for this session.

It can be possible by setting SESSION_SAVE_EVERY_REQUEST to True and by overriding https://github.com/django/django/blob/fc4b4fd5850989458d6e54de12a29b2e40e94ce8/django/contrib/sessions/backends/base.py#L153 to always return False. But in that case, the session cookie will be not deleted because of https://github.com/django/django/blob/fc4b4fd5850989458d6e54de12a29b2e40e94ce8/django/contrib/sessions/middleware.py#L37.

Can there be problems if cookie will remain?

Or maybe there is another way to set sessionid for every visitor?

coldmind
  • 5,167
  • 2
  • 22
  • 22
  • why don't you just add some value into the session of every visitor? – Bastian Jun 29 '16 at 11:36
  • @Bastian Well, this will require additional middleware or modification of an existing one, and also extra space in the session storage. – coldmind Jun 29 '16 at 11:39
  • if you just need a cookie you could simply add that instead of using the session system at all? You will probably need to do that in a middleware regardless what you do. AFAIK sessions are only created when you add something to them. – Bastian Jun 29 '16 at 11:44
  • @Bastian I want to use sessionid cookie as some unique identifier for the current user, and it looks fine, another cookie seems redundant for me. – coldmind Jun 29 '16 at 11:47
  • another cookie would be much less overhead because it would not trigger session loading for each visitor on every request... – Bastian Jun 29 '16 at 11:50

0 Answers0