Delete pieces of Session on browser close

I am going to be storing a significant amount of information inside Django's session cookie. I want this data to persist for the entire time the user is on the website. When he leaves, the data should be deleted, but the session MUST persist. I do not want to user to need to log in every time he returns to the website.

I found ways to purge the entire session cookie every time a user leaves the website, but ideally I would like to only delete select pieces of the cookie which I explicitly set. Does anyone know how to do this?

Answers


You're confusing things a bit.

The only thing stored inside "Django's session cookie" is an ID. That ID refers to the data which is stored inside the session backend: this is usually a database table, but could be a file or cache location depending on your Django configuration.

Now the only time that data is updated is when it is modified by Django. You can't expire data automatically, except by either the cookie itself expiring (in which case the entire set of data persists in the session store, but is no longer associated with the client) or by running a process on the server that modifies sessions programmatically.

There's no way of telling from the server end when a user leaves a website or closes his browser. So the only way of managing this would be to run a cron job on your server that gets sessions that were last modified (say) two hours ago, and iterate through them deleting the data you want to remove.


Need Your Help

Search in SQL database using array PHP

php mysql search

$value = array('one', 'two', 'three');

add up values from 2 arrays based on duplicate values of the other one

ruby arrays

A similar question has been answered here However I'd like to know how I can add up/group the numbers from one array based on the duplicate values of another array.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.