- Timestamp:
- Jun 3, 2014, 10:07:32 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_session.inc.php
r28591 r28615 59 59 * 60 60 * @param int $size 61 * @param string $alphabet chars to use in the key,62 * default is all digits and all letters uppercase and lowercase63 61 * @return string 64 62 */ 65 function generate_key($size, $alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') 66 { 67 $l = strlen($alphabet)-1; 68 $key = ''; 69 for ($i=0; $i<$size; $i++) 70 { 71 $key.= $alphabet[mt_rand(0, $l)]; 72 } 73 return $key; 63 function generate_key($size) 64 { 65 if ( 66 is_callable('openssl_random_pseudo_bytes') 67 and !(version_compare(PHP_VERSION, '5.3.4') < 0 and defined('PHP_WINDOWS_VERSION_MAJOR')) 68 ) 69 { 70 return substr( 71 str_replace( 72 array('+', '/'), 73 '', 74 base64_encode(openssl_random_pseudo_bytes($size)) 75 ), 76 0, 77 $size 78 ); 79 } 80 else 81 { 82 $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 83 $l = strlen($alphabet)-1; 84 $key = ''; 85 for ($i=0; $i<$size; $i++) 86 { 87 $key.= $alphabet[mt_rand(0, $l)]; 88 } 89 return $key; 90 } 74 91 } 75 92
Note: See TracChangeset
for help on using the changeset viewer.