CodeIgniter provides a set of compatibility functions that enable you to use functions what are otherwise natively available in PHP, but only in higher versions or depending on a certain extension.
Being custom implementations, these functions will also have some set of dependencies on their own, but are still useful if your PHP setup doesn’t offer them natively.
Note
Much like the common functions, the compatibility functions are always available, as long as their dependencies are met.
This set of compatibility functions offers a “backport” of PHP’s standard Password Hashing extension that is otherwise available only since PHP 5.5.
CRYPT_BLOWFISH
support for crypt()
PASSWORD_BCRYPT
PASSWORD_DEFAULT
password_get_info($hash)
Parameters: |
|
---|---|
Returns: |
Information about the hashed password |
Return type: |
array |
For more information, please refer to the PHP manual for password_get_info().
password_hash($password, $algo[, $options = array()])
Parameters: |
|
---|---|
Returns: |
Hashed password or FALSE on failure |
Return type: |
string |
For more information, please refer to the PHP manual for password_hash().
Note
Unless you provide your own (and valid) salt, this function has a further dependency on an available CSPRNG source. Each of the following would satisfy that: - mcrypt_create_iv()
with MCRYPT_DEV_URANDOM
- openssl_random_pseudo_bytes()
- /dev/arandom - /dev/urandom
password_needs_rehash()
Parameters: |
|
---|---|
Returns: |
TRUE if the hash should be rehashed to match the given algorithm and options, FALSE otherwise |
Return type: |
bool |
For more information, please refer to the PHP manual for password_needs_rehash().
password_verify($password, $hash)
Parameters: |
|
---|---|
Returns: |
TRUE if the password matches the hash, FALSE if not |
Return type: |
bool |
For more information, please refer to the PHP manual for password_verify().
This compatibility layer contains backports for the hash_equals()
and hash_pbkdf2()
functions, which otherwise require PHP 5.6 and/or PHP 5.5 respectively.
hash_equals($known_string, $user_string)
Parameters: |
|
---|---|
Returns: |
TRUE if the strings match, FALSE otherwise |
Return type: |
string |
For more information, please refer to the PHP manual for hash_equals().
hash_pbkdf2($algo, $password, $salt, $iterations[, $length = 0[, $raw_output = FALSE]])
Parameters: |
|
---|---|
Returns: |
Password-derived key or FALSE on failure |
Return type: |
string |
For more information, please refer to the PHP manual for hash_pbkdf2().
This set of compatibility functions offers limited support for PHP’s Multibyte String extension. Because of the limited alternative solutions, only a few functions are available.
Note
When a character set parameter is ommited, $config['charset']
will be used.
Important
This dependency is optional and these functions will always be declared. If iconv is not available, they WILL fall-back to their non-mbstring versions.
Important
Where a character set is supplied, it must be supported by iconv and in a format that it recognizes.
Note
For you own dependency check on the actual mbstring extension, use the MB_ENABLED
constant.
mb_strlen($str[, $encoding = NULL])
Parameters: |
|
---|---|
Returns: |
Number of characters in the input string or FALSE on failure |
Return type: |
string |
For more information, please refer to the PHP manual for mb_strlen().
mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]])
Parameters: |
|
---|---|
Returns: |
Numeric character position of where $needle was found or FALSE if not found |
Return type: |
mixed |
For more information, please refer to the PHP manual for mb_strpos().
mb_substr($str, $start[, $length = NULL[, $encoding = NULL]])
Parameters: |
|
---|---|
Returns: |
Portion of $str specified by $start and $length or FALSE on failure |
Return type: |
string |
For more information, please refer to the PHP manual for mb_substr().
This set of compatibility functions offers support for a few standard functions in PHP that otherwise require a newer PHP version.
array_column(array $array, $column_key[, $index_key = NULL])
Parameters: |
|
---|---|
Returns: |
An array of values representing a single column from the input array |
Return type: |
array |
For more information, please refer to the PHP manual for array_column().
hex2bin($data)
Parameters: |
|
---|---|
Returns: |
Binary representation of the given data |
Return type: |
string |
For more information, please refer to the PHP manual for hex2bin().
© 2014–2018 British Columbia Institute of Technology
Licensed under the MIT License.
https://www.codeigniter.com/user_guide/general/compatibility_functions.html