Codeigniter Common Functions
CodeIgniter uses a number of functions for its operation that are globally outlined, and are accessible to you at any purpose.
These don't need loading any libraries or helpers.
is_php ($version) |
|
---|---|
Parameters: |
|
Returns: | TRUE if the running PHP version is at least the one specified or FALSE if not |
Return type: | bool |
Determines if the PHP version being used is greater than the supplied version number.
Example:
if (is_php('5.3'))
{
$str = quoted_printable_encode($str);
}
Returns Boolean TRUE if the put-in version of PHP is up to or larger than the provided version range.
Returns FALSE if the put-in version of PHP is not up to the provided version range.
is_really_writable ($file) |
|
---|---|
Parameters: |
|
Returns: | TRUE if the path is writable, FALSE if not |
Return type: | bool |
is_writable() returns TRUE on Windows servers once you extremely can’t write to the file because the OS reports to PHP as FALSE on condition that the read-only attribute is marked.
This performs determines if a file is really writable by making an attempt to put in writing thereto initial.
Generally only suggested on platforms wherever this data is also unreliable.
Example:
if (is_really_writable('file.txt'))
{
echo "I could write to this if I wanted to";
}
else
{
echo "File is not writable";
}
config_item ($key) |
|
---|---|
Parameters: |
|
Returns: | Configuration key-value or NULL if not found |
Return type: | mixed |
The Config Library is the preferred way of accessing configuration information, however, config_item() can be used to retrieve single keys. See Config Library documentation for more information.
set_status_header ($code[, $text = '']) |
|
---|---|
Parameters: |
|
Return type: |
Permits you to manually set a server status header. Example:
set_status_header(401);
// Sets the header as: Unauthorized
remove_invisible_characters ($str[, $url_encoded = TRUE]) |
|
---|---|
Parameters: |
|
Returns: | Sanitized string |
Return type: | string |
This function prevents inserting NULL characters between ASCII characters, like Java\0script.
Example:
remove_invisible_characters('Java\\0script');
// Returns: 'Javascript'
html_escape ($var) |
|
---|---|
Parameters: |
|
Returns: | HTML escaped string(s) |
Return type: | mixed |
This function acts as AN alias for PHP’s native htmlspecialchars() operate, with the advantage of having the ability to simply accept AN array of strings.
It is useful in preventing Cross-Site Scripting (XSS).
get_mimes () |
|
---|---|
Returns: | An associative array of file types |
Return type: | array |
This function returns a reference to the MIMEs array from application/config/mimes.php.
is_https () |
|
---|---|
Returns: | TRUE if currently using HTTP-over-SSL, FALSE if not |
Return type: | bool |
Returns TRUE if a secure (HTTPS) connection is used and FALSE in any other case (including non-HTTP requests).
is_cli () |
|
---|---|
Returns: | TRUE if currently running under CLI, FALSE otherwise |
Return type: | bool |
Returns TRUE if the application is run through the command line and FALSE if not.
PHP_SAPI
value is ‘cli’ or if the STDIN
constant is defined.
function_usable ($function_name) |
|
---|---|
Parameters: |
|
Returns: | TRUE if the function can be used, FALSE if not |
Return type: | bool |
Returns TRUE if a perform exists and is usable, FALSE otherwise.
This function runs a function_exists() check and if the Suhosin extension is loaded, checks if it doesn’t disable the function being checked.
It is useful if you want to check for the availability of functions such as eval() and exec(), which are dangerous and might be disabled on servers with highly restrictive security policies.
Note -
This perform was introduced as a result of Suhosin terminated script execution, but this turned out to be a bug.
A fix has been out there for a few time (version zero.9.34), however, is unfortunately not discharged nonetheless.