Make my session non persistent I created a function to save the location (city, lat, long) of the user. So when he change the page, I don't need to convert his location again. So I've a problem. The session might be saved because when I close my computer, go to another place and reopen the page, my old location is still saved. How I can forget the location of the user when he leave my website ?

Here is a code example for how I store the user location :

function user_location_update($args) {
    drupal_session_start();
    if (isset($_GET['lat']) &amp;&amp; isset($_GET['lng'])) {
        $_SESSION['user-location'] = array(
            'lat' =&gt; $_GET['lat'],
            'lng' =&gt; $_GET['lng'],
            'city' =&gt; $_GET['city'],
        );
    } else {
        $_SESSION['user-location'] = array(
            'city' =&gt; $_GET['city'],
        );
    }       
}


Then here is an example how I use my data (I send them to JS by settings) :

drupal_add_js(array('userlocation' =&gt; (isset($_SESSION['user-location']) ? $_SESSION['user-location'] : array())), 'setting');
This is the best advice:
https://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php

To put it in a Drupal context, you'd have to add a new column to the user table that tracked the last time a user was active and check that on a user hook.