Ignore:
Timestamp:
Jul 27, 2003, 10:24:10 AM (21 years ago)
Author:
z0rglub
Message:

optional cookie identification

File:
1 edited

Legend:

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

    r14 r45  
    1515 *                                                                         *
    1616 ***************************************************************************/
     17
     18// The function generate_key creates a string with pseudo random characters.
     19// the size of the string depends on the $conf['session_id_size'].
     20// Characters used are a-z A-Z and numerical values. Examples :
     21//                    "Er4Tgh6", "Rrp08P", "54gj"
     22// input  : none (using global variable)
     23// output : $key
    1724function generate_key()
    1825{
    1926  global $conf;
     27
    2028  $md5 = md5( substr( microtime(), 2, 6 ).$conf['session_keyword'] );
    2129  $init = '';
    2230  for ( $i = 0; $i < strlen( $md5 ); $i++ )
    2331  {
    24     if ( is_numeric( $md5[$i] ) )
    25     {
    26       $init.= $md5[$i];
    27     }
     32    if ( is_numeric( $md5[$i] ) ) $init.= $md5[$i];
    2833  }
    2934  $init = substr( $init, 0, 8 );
     
    3338  {
    3439    $c = mt_rand( 0, 2 );
    35     if ( $c == 0 )
    36     {
    37       $key .= chr( mt_rand( 65, 90 ) );
    38     }
    39     else if ( $c == 1 )
    40     {
    41       $key .= chr( mt_rand( 97, 122 ) );
    42     }
    43     else
    44     {
    45       $key .= mt_rand( 0, 9 );
    46     }
     40    if ( $c == 0 )      $key .= chr( mt_rand( 65, 90 ) );
     41    else if ( $c == 1 ) $key .= chr( mt_rand( 97, 122 ) );
     42    else                $key .= mt_rand( 0, 9 );
    4743  }
    4844  return $key;
    4945}
    50        
     46
     47// The function create_session finds a non-already-used session key and
     48// returns it once found for the given user.
    5149function session_create( $username )
    5250{
    5351  global $conf;
    54   // 1. searching an unused sesison key
     52  // 1. searching an unused session key
    5553  $id_found = false;
    5654  while ( !$id_found )
     
    9088{
    9189  global $page, $user;
     90
     91  if ( $user['has_cookie'] ) return $url;
     92
    9293  $amp = '&amp;';
    9394  if ( $redirect )
     
    111112  }
    112113}
     114
     115// cookie_path returns the path to use for the PhpWebGallery cookie.
     116// If PhpWebGallery is installed on :
     117// http://domain.org/meeting/gallery/category.php
     118// cookie_path will return : "/meeting/gallery"
     119function cookie_path()
     120{
     121  return substr($_SERVER['PHP_SELF'],0,strrpos( $_SERVER['PHP_SELF'],'/'));
     122}
    113123?>
Note: See TracChangeset for help on using the changeset viewer.