Changeset 1010


Ignore:
Timestamp:
01/21/06 11:56:36 (14 years ago)
Author:
nikrou
Message:

improve sessions: add comments to functions

File:
1 edited

Legend:

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

    r1007 r1010  
    3737  ); 
    3838} 
    39 if (isset($conf['session_use_cookies']))  
    40 {  
    41   ini_set('session.use_cookies', $conf['session_use_cookies']); 
    42 } 
    43 if (isset($conf['session_use_only_cookies'])) 
    44 { 
    45   ini_set('session.use_only_cookies', $conf['session_use_only_cookies']); 
    46 } 
    47 if (isset($conf['session_use_trans_sid'])) 
    48 { 
    49   ini_set('session.use_trans_sid', intval($conf['session_use_trans_sid'])); 
    50 } 
    51 if (isset($conf['session_name'])) 
    52 { 
    53   ini_set('session.name', $conf['session_name']); 
    54 } 
     39  
     40ini_set('session.use_cookies', $conf['session_use_cookies']); 
     41ini_set('session.use_only_cookies', $conf['session_use_only_cookies']); 
     42ini_set('session.use_trans_sid', intval($conf['session_use_trans_sid'])); 
     43ini_set('session.name', $conf['session_name']); 
    5544 
     45/** 
     46 * returns true; used when the session_start() function is called 
     47 * 
     48 * @params not use but useful for php engine 
     49 */ 
    5650function pwg_session_open($path, $name)  
    5751{ 
     
    5953} 
    6054 
     55/** 
     56 * returns true; used when the session is closed (unset($_SESSION)) 
     57 * 
     58 */ 
    6159function pwg_session_close()  
    6260{ 
     
    6563} 
    6664 
     65/** 
     66 * this function returns 
     67 * a string corresponding to the value of the variable save in the session  
     68 * or an empty string when the variable doesn't exist 
     69 *  
     70 * @param string session id 
     71 */ 
    6772function pwg_session_read($session_id)  
    6873{ 
    6974  $query = ' 
    70 SELECT data FROM '.SESSIONS_TABLE.' 
    71   WHERE id = \''.$session_id.'\''; 
     75SELECT data  
     76  FROM '.SESSIONS_TABLE.' 
     77  WHERE id = \''.$session_id.'\' 
     78;'; 
    7279  $result = pwg_query($query); 
    7380  if ($result)  
     
    8289} 
    8390 
     91/** 
     92 * returns true; writes set a variable in the active session  
     93 *  
     94 * @param string session id 
     95 * @data string value of date to be saved 
     96 */ 
    8497function pwg_session_write($session_id, $data)  
    8598{ 
    8699  $query = ' 
    87 SELECT id FROM '.SESSIONS_TABLE.' 
    88   WHERE id = \''.$session_id.'\''; 
     100SELECT id  
     101  FROM '.SESSIONS_TABLE.' 
     102  WHERE id = \''.$session_id.'\' 
     103;'; 
    89104  $result = pwg_query($query); 
    90105  if (mysql_num_rows($result))  
    91106  { 
    92107    $query = ' 
    93 UPDATE '.SESSIONS_TABLE.' SET expiration = now() 
    94   WHERE id = \''.$session_id.'\'';     
     108UPDATE '.SESSIONS_TABLE.'  
     109  SET expiration = now() 
     110  WHERE id = \''.$session_id.'\' 
     111;';     
    95112    pwg_query($query); 
    96113  }  
     
    98115  { 
    99116    $query = ' 
    100 INSERT INTO '.SESSIONS_TABLE.'(id,data,expiration) 
    101   VALUES(\''.$session_id.'\',\''.$data.'\',now())'; 
     117INSERT INTO '.SESSIONS_TABLE.'  
     118  (id,data,expiration) 
     119  VALUES(\''.$session_id.'\',\''.$data.'\',now()) 
     120;'; 
    102121    pwg_query($query);     
    103122  } 
     
    105124} 
    106125 
     126/** 
     127 * returns true; delete the active session  
     128 *  
     129 * @param string session id 
     130 */ 
    107131function pwg_session_destroy($session_id)  
    108132{ 
    109133  $query = ' 
    110 DELETE FROM '.SESSIONS_TABLE.' 
    111   WHERE id = '.$session_id; 
     134DELETE  
     135  FROM '.SESSIONS_TABLE.' 
     136  WHERE id = \''.$session_id.'\' 
     137;'; 
    112138  pwg_query($query); 
    113139  return true; 
    114140} 
    115141 
     142/** 
     143 * returns true; delete expired sessions 
     144 * called each time a session is closed. 
     145 */ 
    116146function pwg_session_gc()  
    117147{ 
     
    119149 
    120150  $query = ' 
    121 DELETE FROM '.SESSIONS_TABLE.' 
     151DELETE  
     152  FROM '.SESSIONS_TABLE.' 
    122153  WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(expiration) > ' 
    123   .$conf['session_length']; 
     154  .$conf['session_length'].' 
     155;'; 
    124156  pwg_query($query); 
    125157  return true; 
Note: See TracChangeset for help on using the changeset viewer.