Source for file session.php
Documentation is available at session.php
* Session constants and tools
* @author Jean-Philippe Brunon <jp75018@free.fr>
* @copyright 2007-2009 Jean-Philippe Brunon
* @license http://www.opensource.org/licenses/gpl-license.php GPL
* @version $Id: session.php 66 2009-03-26 10:39:25Z jp75018 $
* General configuration file
require_once ('conf/config.php');
* Recursive delete mode : Remove only files (keep directory structure intact)
* Recursive delete mode : Remove all except root directory
define('DIR_REMOVE_SUBDIR', 2);
* Recursive delete mode : Remove all
* Call instead of session_start() to start sessions.
* Cleanup temporary files
* ($GLOBALS['tmp_dir'] and $GLOBALS['upload_dir'] directories).
@ini_set('session.gc_maxlifetime', $GLOBALS['session_gc_maxlifetime']);
if (isset
($_POST['lang']))
{ unset
($_SESSION['lang']); } // Language change
if (isset
($_SESSION['lang']))
{ $lang =
$_SESSION['lang']; } // Language already set in session
if ((! $lang) && isset
($_POST['lang']))
// Case of language change
if (! file_exists('lang/strings_' .
$lang .
'.inc.php'))
// Language stored in cookie?
{ $lang =
$_COOKIE['lang']; }
// If no language : Use browser language if supported, else use def language
if (! file_exists('lang/strings_' .
$lang .
'.inc.php'))
{ $lang =
$GLOBALS['def_lang']; } // If still KO => Get default language
// Get browser width and height
{ $_SESSION['browser_width'] =
$_COOKIE['browser_width']; }
{ unset
($_SESSION['browser_width']); }
// Get preferences from cookies
$_SESSION['pref_display_width'] =
$_COOKIE['pref_display_width'];
// Cleanup tmp and upload directories
if ((($_SESSION['http_count']+
$ts) %
100) <
$GLOBALS['garbage_collect_proba'])
$d =
dir($GLOBALS['tmp_dir']);
while (($file =
$d->read()) !==
false)
if (($file ==
'.') ||
($file ==
'..'))
if (($ts -
@filemtime($GLOBALS['tmp_dir'] .
$file)) >=
$GLOBALS['tmp_files_duration'])
{ @unlink($GLOBALS['tmp_dir'] .
$file); }
// Cleanup all users upload directories (recursive)
// Do not remove 'upload' directory itself, even if empty
// Always cleanup user upload directory (recursive)
if ($_SESSION['my_user_id'])
str_pad($_SESSION['my_user_id'], 6, '0', STR_PAD_LEFT),
$_SESSION['http_count']++
;
* Get language from browser language string (take preferred language)
* @param string $browser_language Browser language string
* @return string Language ISO code : xx or xx-YY of preferred language
* or null if no language found
$lang_tab =
explode(',', $browser_language);
for ($i =
0; $i <
count($lang_tab); $i++
)
if (preg_match('/^\s*([^;\s]+)\s*(;\s*q\s*=\s*([0-9]*\.?[0-9]*))?\s*$/i',
$lang_tab[$i], $matches))
{ $priority =
$matches[3]; }
if ($priority >
$max_priority)
$max_priority =
$priority;
* Set language in session
* @param string $lang Language to set (2 letters ISO code)
if ($lang &&
($lang !=
$_SESSION['lang']))
{ require_once ('lang/strings_' .
$lang .
'.inc.php'); }
$_SESSION['lang'] =
$lang;
$GLOBALS['lang'] =
$lang;
* Get total size of files in a directory (recursively or not)
* Note : Each file size is rounded up assuming default block size.
* @param string $dir_name Directory name (relative to site root)
* @param string $recur true to consider subdirectories, else false
* @return integer Cumulated size in bytes, 0 on error
$dir_handler =
@dir($dir_name);
while (($entry =
$dir_handler->read()) !==
false)
if (($entry ==
'.') ||
($entry ==
'..') ||
($entry ==
'.svn'))
$entry =
$dir_name .
'/' .
$entry;
$file_stat =
@stat($entry);
$file_size =
$file_stat['size'] +
($file_size ?
0 :
1);
$cum_size +=
$GLOBALS['fs_block_size'] *
ceil($file_size /
$GLOBALS['fs_block_size']);
* Recursive delete a directory
* Remove subdirs / dir only if all files in subdirs / dir are removed.
* @param string $dir_name Directory name (relative to site root)
* @param integer $age Remove only files modified more than <age>
* seconds ago (all if = 0)
* @param string $mode Delete mode (see DIR_REMOVE_*)
* @param integer $ts Current timestamp. Do not use, avoid calling time().
* @return boolean true if directory was removed, else false.
$age =
0, $mode =
DIR_REMOVE_SUBDIR, $ts =
null)
$dir_handler =
@dir($dir_name);
while (($entry =
$dir_handler->read()) !==
false)
if (($entry ==
'.') ||
($entry ==
'..') ||
($entry ==
'.svn'))
$entry =
$dir_name .
'/' .
$entry;
$file_stat =
@stat($entry);
$file_age =
$ts -
$file_stat['mtime'];
// Remove directory if empty
if ($entry_nb ==
$del_nb)
* Start timer to measure performance
* @return float Unix timestamp in microseconds.
return ((float)
$usec + (float)
$sec);
* Stop timer to measure performance
* @param float $start Timestamp returned by timer_start().
* @return float Elapsed real time in microseconds between timer_start()
Documentation generated on Sat, 28 Mar 2009 23:17:13 +0000 by phpDocumentor 1.4.1