Changeset 28591


Ignore:
Timestamp:
Jun 2, 2014, 2:52:00 PM (10 years ago)
Author:
mistic100
Message:

use lookup string for generate_key function

File:
1 edited

Legend:

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

    r28571 r28591  
    5959 *
    6060 * @param int $size
     61 * @param string $alphabet chars to use in the key,
     62 *    default is all digits and all letters uppercase and lowercase
    6163 * @return string
    6264 */
    63 function generate_key($size)
    64 {
     65function generate_key($size, $alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
     66{
     67  $l = strlen($alphabet)-1;
    6568  $key = '';
    66   for ( $i = 0; $i < $size; $i++ )
    67   {
    68     $c = mt_rand( 0, 2 );
    69     if ( $c == 0 )      $key .= chr( mt_rand( 65, 90 ) );
    70     else if ( $c == 1 ) $key .= chr( mt_rand( 97, 122 ) );
    71     else                $key .= mt_rand( 0, 9 );
     69  for ($i=0; $i<$size; $i++)
     70  {
     71    $key.= $alphabet[mt_rand(0, $l)];
    7272  }
    7373  return $key;
Note: See TracChangeset for help on using the changeset viewer.