fix last commit, invalit conditional due missing parentesis * related to commit 3c9fcc8
fix deprecation warning messages
Fix upcoming deprecation of mt_rand on newer php versions * provide a workaround function in code/Common like is_php does * closes bcit-ci/CodeIgniter#6275 * related to pocketarc/codeigniter#3 (comment)
... | ... | @@ -60,33 +60,34 @@ if ( ! function_exists('is_php')) |
60 | 60 | /**
|
61 | 61 | * implements internally the rand specific function based on PHP version, used internally
|
62 | 62 | *
|
63 | - * @access public
|
|
64 | - * @param int or 0
|
|
65 | - * @param int or mt_getrandmax()
|
|
66 | - * @return int
|
|
63 | + * @access public
|
|
64 | + * @param int or 0
|
|
65 | + * @param int or mt_getrandmax()
|
|
66 | + * @return int
|
|
67 | 67 | */
|
68 | 68 | if ( ! function_exists('php_rand'))
|
69 | 69 | {
|
70 | - /**
|
|
71 | - * implements internally the rand specific function based on PHP version, used internally
|
|
72 | - *
|
|
73 | - * @param int or 0
|
|
74 | - * @param int or mt_getrandmax()
|
|
75 | - * @return int
|
|
76 | - */
|
|
77 | - function php_rand($min = NULL, $max = NULL)
|
|
78 | - {
|
|
79 | - if(!is_int($min) $min = 0;
|
|
80 | - if(!is_int($max) $max = mt_getrandmax();
|
|
81 | - |
|
82 | - if( is_php('7.1.99') ) return random_int($min, $max);
|
|
83 | - |
|
84 | - if (!function_exists('mcrypt_create_iv')) trigger_error( 'mcrypt must be loaded for random_int to work', E_USER_WARNING );
|
|
85 | - |
|
86 | - return mt_rand($min, $max);
|
|
87 | - }
|
|
70 | + /**
|
|
71 | + * implements internally the rand specific function based on PHP version, used internally
|
|
72 | + *
|
|
73 | + * @param int or 0
|
|
74 | + * @param int or mt_getrandmax()
|
|
75 | + * @return int
|
|
76 | + */
|
|
77 | + function php_rand($min = NULL, $max = NULL)
|
|
78 | + {
|
|
79 | + if( is_php('7.1.99') ) return random_int($min, $max);
|
|
80 | + |
|
81 | + if(!is_int($min)) $min = 0;
|
|
82 | + if(!is_int($max)) $max = mt_getrandmax();
|
|
83 | + |
|
84 | + if (!function_exists('mcrypt_create_iv')) trigger_error( 'mcrypt must be loaded for random_int to work', E_USER_WARNING );
|
|
85 | + |
|
86 | + return mt_rand($min, $max);
|
|
87 | + }
|
|
88 | 88 | }
|
89 | 89 | |
90 | + |
|
90 | 91 | // ------------------------------------------------------------------------
|
91 | 92 | |
92 | 93 | /**
|
... | ... | @@ -113,7 +114,7 @@ if ( ! function_exists('is_really_writable')) |
113 | 114 | // write a file then read it. Bah...
|
114 | 115 | if (is_dir($file))
|
115 | 116 | {
|
116 | - $file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100));
|
|
117 | + $file = rtrim($file, '/').'/'.md5(php_rand(1,100).php_rand(1,100));
|
|
117 | 118 | |
118 | 119 | if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
|
119 | 120 | {
|
... | ... | @@ -559,7 +559,7 @@ class CI_Input { |
559 | 559 | break;
|
560 | 560 | }
|
561 | 561 | |
562 | - return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
|
|
562 | + return (bool) filter_var($ip, FILTER_VALIDATE_IP, array('flags'=>$flag));
|
|
563 | 563 | }
|
564 | 564 | |
565 | 565 | if ($which !== 'ipv6' && $which !== 'ipv4')
|
... | ... | @@ -488,7 +488,7 @@ class CI_Security { |
488 | 488 | if ($this->_xss_hash == '')
|
489 | 489 | {
|
490 | 490 | mt_srand();
|
491 | - $this->_xss_hash = md5(time() + php_rand(0, 1999999999));
|
|
491 | + $this->_xss_hash = md5(time() + is_php('8.3') ? mt_rand(0,1999999999) : random_int(0,1999999999) );
|
|
492 | 492 | }
|
493 | 493 | |
494 | 494 | return $this->_xss_hash;
|
... | ... | @@ -187,7 +187,7 @@ if ( ! function_exists('create_captcha')) |
187 | 187 | {
|
188 | 188 | for ($i = 0; $i < $word_length; $i++)
|
189 | 189 | {
|
190 | - $word .= $pool[php_rand(0, $rand_max)];
|
|
190 | + $word .= $pool[is_php('8.3') ? mt_rand(0,$rand_max) : random_int(0, $rand_max)];
|
|
191 | 191 | }
|
192 | 192 | }
|
193 | 193 | elseif ( ! is_string($word))
|
... | ... | @@ -197,7 +197,7 @@ if ( ! function_exists('random_string')) |
197 | 197 | {
|
198 | 198 | switch($type)
|
199 | 199 | {
|
200 | - case 'basic' : return php_rand();
|
|
200 | + case 'basic' : return is_php('8.3') ? mt_rand((mt_getrandmax()*-1),mt_getrandmax()) : random_int(PHP_INT_MIN, PHP_INT_MAX);
|
|
201 | 201 | break;
|
202 | 202 | case 'alnum' :
|
203 | 203 | case 'numeric' :
|
... | ... | @@ -219,14 +219,14 @@ if ( ! function_exists('random_string')) |
219 | 219 | $str = '';
|
220 | 220 | for ($i=0; $i < $len; $i++)
|
221 | 221 | {
|
222 | - $str .= substr($pool, php_rand(0, strlen($pool) -1), 1);
|
|
222 | + $str .= substr($pool, (is_php('8.3') ? mt_rand(0, strlen($pool) -1) : random_int(0, strlen($pool) -1)), 1);
|
|
223 | 223 | }
|
224 | 224 | return $str;
|
225 | 225 | break;
|
226 | 226 | case 'unique' :
|
227 | 227 | case 'md5' :
|
228 | 228 | |
229 | - return md5(uniqid(php_rand()));
|
|
229 | + return md5(uniqid(is_php('8.3') ? mt_rand((mt_getrandmax()*-1),mt_getrandmax()) : random_int(PHP_INT_MIN, PHP_INT_MAX)));
|
|
230 | 230 | break;
|
231 | 231 | case 'encrypt' :
|
232 | 232 | case 'sha1' :
|
... | ... | @@ -234,7 +234,7 @@ if ( ! function_exists('random_string')) |
234 | 234 | $CI =& get_instance();
|
235 | 235 | $CI->load->helper('security');
|
236 | 236 | |
237 | - return do_hash(uniqid(php_rand(), TRUE), 'sha1');
|
|
237 | + return do_hash(uniqid((is_php('8.3') ? mt_rand((mt_getrandmax()*-1),mt_getrandmax()) : random_int(PHP_INT_MIN, PHP_INT_MAX)), TRUE), 'sha1');
|
|
238 | 238 | break;
|
239 | 239 | }
|
240 | 240 | }
|
... | ... | @@ -247,7 +247,7 @@ class CI_Encrypt { |
247 | 247 | $rand = '';
|
248 | 248 | while (strlen($rand) < 32)
|
249 | 249 | {
|
250 | - $rand .= php_rand(0, mt_getrandmax());
|
|
250 | + $rand .= is_php('8.3') ? mt_rand(0,mt_getrandmax()) : random_int(0, PHP_INT_MAX);
|
|
251 | 251 | }
|
252 | 252 | |
253 | 253 | $rand = $this->hash($rand);
|
... | ... | @@ -69,7 +69,7 @@ class CI_Log { |
69 | 69 | * @param bool whether the error is a native PHP error
|
70 | 70 | * @return bool
|
71 | 71 | */
|
72 | - public function write_log($level = 'error', $msg, $php_error = FALSE)
|
|
72 | + public function write_log($level = 'error', $msg = NULL, $php_error = FALSE)
|
|
73 | 73 | {
|
74 | 74 | if ($this->_enabled === FALSE)
|
75 | 75 | {
|
... | ... | @@ -328,7 +328,7 @@ class CI_Session { |
328 | 328 | $sessid = '';
|
329 | 329 | while (strlen($sessid) < 32)
|
330 | 330 | {
|
331 | - $sessid .= php_rand(0, mt_getrandmax());
|
|
331 | + $sessid .= is_php('8.3') ? mt_rand(0,mt_getrandmax()) : random_int(0, PHP_INT_MAX);
|
|
332 | 332 | }
|
333 | 333 | |
334 | 334 | // To make the session ID even more secure we'll combine it with the user's IP
|
... | ... | @@ -375,7 +375,7 @@ class CI_Session { |
375 | 375 | $new_sessid = '';
|
376 | 376 | while (strlen($new_sessid) < 32)
|
377 | 377 | {
|
378 | - $new_sessid .= php_rand(0, mt_getrandmax());
|
|
378 | + $new_sessid .= is_php('8.3') ? mt_rand(0,mt_getrandmax()) : random_int(0, PHP_INT_MAX);
|
|
379 | 379 | }
|
380 | 380 | |
381 | 381 | // To make the session ID even more secure we'll combine it with the user's IP
|
... | ... | @@ -397,7 +397,7 @@ class CI_Upload { |
397 | 397 | if ($this->encrypt_name == TRUE)
|
398 | 398 | {
|
399 | 399 | mt_srand();
|
400 | - $filename = md5(uniqid(php_rand())).$this->file_ext;
|
|
400 | + $filename = md5(uniqid( is_php('8.3') ? mt_rand((mt_getrandmax()*-1),mt_getrandmax()) : random_int(PHP_INT_MIN, PHP_INT_MAX) )).$this->file_ext;
|
|
401 | 401 | }
|
402 | 402 | |
403 | 403 | if ( ! file_exists($path.$filename)) // if ($this->overwrite === TRUE OR ! file_exists($path.$filename)) // permite que asigne nombre nuevo no importa si esta permitido
|
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help