Index: trunk/include/config.inc.php
===================================================================
--- trunk/include/config.inc.php	(revision 44)
+++ trunk/include/config.inc.php	(revision 45)
@@ -63,5 +63,5 @@
                 'upload_maxheight', 'upload_maxwidth_thumbnail',
                 'upload_maxheight_thumbnail','log','comments_validation',
-                'comments_forall' );
+                'comments_forall','authorize_cookies' );
 
 $query  = 'SELECT ';
Index: trunk/include/functions_session.inc.php
===================================================================
--- trunk/include/functions_session.inc.php	(revision 44)
+++ trunk/include/functions_session.inc.php	(revision 45)
@@ -15,15 +15,20 @@
  *                                                                         *
  ***************************************************************************/
+
+// The function generate_key creates a string with pseudo random characters.
+// the size of the string depends on the $conf['session_id_size'].
+// Characters used are a-z A-Z and numerical values. Examples :
+//                    "Er4Tgh6", "Rrp08P", "54gj"
+// input  : none (using global variable)
+// output : $key
 function generate_key()
 {
   global $conf;
+
   $md5 = md5( substr( microtime(), 2, 6 ).$conf['session_keyword'] );
   $init = '';
   for ( $i = 0; $i < strlen( $md5 ); $i++ )
   {
-    if ( is_numeric( $md5[$i] ) )
-    {
-      $init.= $md5[$i];
-    }
+    if ( is_numeric( $md5[$i] ) ) $init.= $md5[$i];
   }
   $init = substr( $init, 0, 8 );
@@ -33,24 +38,17 @@
   {
     $c = mt_rand( 0, 2 );
-    if ( $c == 0 )
-    {
-      $key .= chr( mt_rand( 65, 90 ) );
-    }
-    else if ( $c == 1 )
-    {
-      $key .= chr( mt_rand( 97, 122 ) );
-    }
-    else
-    {
-      $key .= mt_rand( 0, 9 );
-    }
+    if ( $c == 0 )      $key .= chr( mt_rand( 65, 90 ) );
+    else if ( $c == 1 ) $key .= chr( mt_rand( 97, 122 ) );
+    else                $key .= mt_rand( 0, 9 );
   }
   return $key;
 }
-        
+
+// The function create_session finds a non-already-used session key and
+// returns it once found for the given user.
 function session_create( $username )
 {
   global $conf;
-  // 1. searching an unused sesison key
+  // 1. searching an unused session key
   $id_found = false;
   while ( !$id_found )
@@ -90,4 +88,7 @@
 {
   global $page, $user;
+
+  if ( $user['has_cookie'] ) return $url;
+
   $amp = '&amp;';
   if ( $redirect )
@@ -111,3 +112,12 @@
   }
 }
+
+// cookie_path returns the path to use for the PhpWebGallery cookie.
+// If PhpWebGallery is installed on :
+// http://domain.org/meeting/gallery/category.php
+// cookie_path will return : "/meeting/gallery"
+function cookie_path()
+{
+  return substr($_SERVER['PHP_SELF'],0,strrpos( $_SERVER['PHP_SELF'],'/'));
+}
 ?>
Index: trunk/include/user.inc.php
===================================================================
--- trunk/include/user.inc.php	(revision 44)
+++ trunk/include/user.inc.php	(revision 45)
@@ -33,11 +33,31 @@
 $query_done = false;
 $user['is_the_guest'] = false;
-if ( isset( $_GET['id'] )
-     && ereg( "^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $_GET['id'] ) )
+
+// cookie deletion if administrator don't authorize them anymore
+if ( !$conf['authorize_cookies'] and isset( $_COOKIE['id'] ) )
 {
-  $page['session_id'] = $_GET['id'];
+  setcookie( 'id', '', 0, cookie_path() );
+  $url = 'category.php';
+  header( 'Request-URI: '.$url );  
+  header( 'Content-Location: '.$url );  
+  header( 'Location: '.$url );
+  exit();
+}
+
+$user['has_cookie'] = false;
+if     ( isset( $_GET['id']    ) ) $session_id = $_GET['id'];
+elseif ( isset( $_COOKIE['id'] ) )
+{
+  $session_id = $_COOKIE['id'];
+  $user['has_cookie'] = true;
+}
+
+if ( isset( $session_id )
+     and ereg( "^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $session_id ) )
+{
+  $page['session_id'] = $session_id;
   $query = 'SELECT user_id,expiration,ip';
   $query.= ' FROM '.PREFIX_TABLE.'sessions';
-  $query.= " WHERE id = '".$_GET['id']."'";
+  $query.= " WHERE id = '".$page['session_id']."'";
   $query.= ';';
   $result = mysql_query( $query );
@@ -45,15 +65,15 @@
   {
     $row = mysql_fetch_array( $result );
-    if ( $row['expiration'] < time() )
+    if ( !$user['has_cookie'] )
     {
-      // deletion of the session from the database,
-      // because it is out-of-date
-      $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions';
-      $delete_query.= " WHERE id = '".$page['session_id']."'";
-      $delete_query.= ';';
-      mysql_query( $delete_query );
-    }
-    else
-    {
+      if ( $row['expiration'] < time() )
+      {
+        // deletion of the session from the database,
+        // because it is out-of-date
+        $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions';
+        $delete_query.= " WHERE id = '".$page['session_id']."'";
+        $delete_query.= ';';
+        mysql_query( $delete_query );
+      }
       if ( $_SERVER['REMOTE_ADDR'] == $row['ip'] )
       {
@@ -61,4 +81,9 @@
         $query_done = true;
       }
+    }
+    else
+    {
+      $query_user .= ' WHERE id = '.$row['user_id'];
+      $query_done = true;
     }
   }
