Ignore:
Timestamp:
Nov 21, 2013, 11:02:44 AM (10 years ago)
Author:
mistic100
Message:

feature 2999: documentation of functions_rate and functions_session

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_session.inc.php

    r20281 r25614  
    2222// +-----------------------------------------------------------------------+
    2323
    24 // The function generate_key creates a string with pseudo random characters.
    25 // the size of the string depends on the $conf['session_id_size'].
    26 // Characters used are a-z A-Z and numerical values. Examples :
    27 //                    "Er4Tgh6", "Rrp08P", "54gj"
    28 // input  : none (using global variable)
    29 // output : $key
    30 function generate_key($size)
    31 {
    32   global $conf;
    33 
    34   $md5 = md5(substr(microtime(), 2, 6));
    35   $init = '';
    36   for ( $i = 0; $i < strlen( $md5 ); $i++ )
    37   {
    38     if ( is_numeric( $md5[$i] ) ) $init.= $md5[$i];
    39   }
    40   $init = substr( $init, 0, 8 );
    41   mt_srand( $init );
    42   $key = '';
    43   for ( $i = 0; $i < $size; $i++ )
    44   {
    45     $c = mt_rand( 0, 2 );
    46     if ( $c == 0 )      $key .= chr( mt_rand( 65, 90 ) );
    47     else if ( $c == 1 ) $key .= chr( mt_rand( 97, 122 ) );
    48     else                $key .= mt_rand( 0, 9 );
    49   }
    50   return $key;
    51 }
     24/**
     25 * @package functions\session
     26 */
     27
    5228
    5329if (isset($conf['session_save_handler'])
     
    5531  and defined('PHPWG_INSTALLED'))
    5632{
    57   session_set_save_handler('pwg_session_open',
     33  session_set_save_handler(
     34    'pwg_session_open',
    5835    'pwg_session_close',
    5936    'pwg_session_read',
     
    6239    'pwg_session_gc'
    6340  );
    64   if ( function_exists('ini_set') )
     41
     42  if (function_exists('ini_set'))
    6543  {
    6644    ini_set('session.use_cookies', $conf['session_use_cookies']);
     
    6947    ini_set('session.cookie_httponly', 1);
    7048  }
     49
    7150  session_name($conf['session_name']);
    7251  session_set_cookie_params(0, cookie_path());
     
    7453}
    7554
    76 /**
    77  * returns true; used when the session_start() function is called
    78  *
    79  * @params not use but useful for php engine
     55
     56/**
     57 * Generates a pseudo random string.
     58 * Characters used are a-z A-Z and numerical values.
     59 *
     60 * @param int $size
     61 * @return string
     62 */
     63function generate_key($size)
     64{
     65  global $conf;
     66
     67  $md5 = md5(substr(microtime(), 2, 6));
     68  $init = '';
     69  for ( $i = 0; $i < strlen( $md5 ); $i++ )
     70  {
     71    if ( is_numeric( $md5[$i] ) ) $init.= $md5[$i];
     72  }
     73  $init = substr( $init, 0, 8 );
     74  mt_srand( $init );
     75  $key = '';
     76  for ( $i = 0; $i < $size; $i++ )
     77  {
     78    $c = mt_rand( 0, 2 );
     79    if ( $c == 0 )      $key .= chr( mt_rand( 65, 90 ) );
     80    else if ( $c == 1 ) $key .= chr( mt_rand( 97, 122 ) );
     81    else                $key .= mt_rand( 0, 9 );
     82  }
     83  return $key;
     84}
     85
     86/**
     87 * Called by PHP session manager, always return true.
     88 *
     89 * @param string $path
     90 * @param sring $name
     91 * @return true
    8092 */
    8193function pwg_session_open($path, $name)
     
    8597
    8698/**
    87  * returns true; used when the session is closed (unset($_SESSION))
    88  *
     99 * Called by PHP session manager, always return true.
     100 *
     101 * @return true
    89102 */
    90103function pwg_session_close()
     
    93106}
    94107
     108/**
     109 * Returns a hash from current user IP
     110 *
     111 * @return string
     112 */
    95113function get_remote_addr_session_hash()
    96114{
     
    113131
    114132/**
    115  * this function returns
    116  * a string corresponding to the value of the variable save in the session
    117  * or an empty string when the variable doesn't exist
    118  *
    119  * @param string session id
     133 * Called by PHP session manager, retrieves data stored in the sessions table.
     134 *
     135 * @param string $session_id
     136 * @return string
    120137 */
    121138function pwg_session_read($session_id)
     
    139156
    140157/**
    141  * returns true; writes set a variable in the active session
    142  *
    143  * @param string session id
    144  * @data string value of date to be saved
     158 * Called by PHP session manager, writes data in the sessions table.
     159 *
     160 * @param string $session_id
     161 * @param sring $data
     162 * @return true
    145163 */
    146164function pwg_session_write($session_id, $data)
     
    156174
    157175/**
    158  * returns true; delete the active session
    159  *
    160  * @param string session id
     176 * Called by PHP session manager, deletes data in the sessions table.
     177 *
     178 * @param string $session_id
     179 * @return true
    161180 */
    162181function pwg_session_destroy($session_id)
     
    172191
    173192/**
    174  * returns true; delete expired sessions
    175  * called each time a session is closed.
     193 * Called by PHP session manager, garbage collector for expired sessions.
     194 *
     195 * @return true
    176196 */
    177197function pwg_session_gc()
     
    189209}
    190210
    191 
    192 /**
    193  * persistently stores a variable for the current session
    194  * currently we use standard php sessions but it might change
    195  * @return boolean true on success
    196  * @see pwg_get_session_var, pwg_unset_session_var
     211/**
     212 * Persistently stores a variable for the current session.
     213 *
     214 * @param string $var
     215 * @param mixed $value
     216 * @return bool
    197217 */
    198218function pwg_set_session_var($var, $value)
     
    205225
    206226/**
    207  * retrieves the value of a persistent variable for the current session
    208  * currently we use standard php sessions but it might change
     227 * Retrieves the value of a persistent variable for the current session.
     228 *
     229 * @param string $var
     230 * @param mixed $default
    209231 * @return mixed
    210  * @see pwg_set_session_var, pwg_unset_session_var
    211232 */
    212233function pwg_get_session_var($var, $default = null)
     
    220241
    221242/**
    222  * deletes a persistent variable for the current session
    223  * currently we use standard php sessions but it might change
    224  * @return boolean true on success
    225  * @see pwg_set_session_var, pwg_get_session_var
     243 * Deletes a persistent variable for the current session.
     244 *
     245 * @param string $var
     246 * @return bool
    226247 */
    227248function pwg_unset_session_var($var)
Note: See TracChangeset for help on using the changeset viewer.