Security Helper¶
The Security Helper file contains security-related functions.
Loading this Helper¶
This helper is loaded using the following code:
<?php
helper('security');
Available Functions¶
The following functions are available:
sanitize_filename($filename[, $relativePath = false])¶
-
Parameters
- $filename
stringFilename - $relativePath
boolWhether the relative path is acceptable (available since v4.6.2)
- $filename
-
Returns: Sanitized file name
-
Return type:
string
Provides protection against directory traversal.
Backslashes are always removed. If $relativePath is true, forward slashes are preserved to allow relative paths such as path/to/file.txt, while parent-directory sequences (../) are removed.
Note
When passing relative paths to this helper, use forward slashes (/) as directory separators, including on Windows.
For more info, please see the Security Library documentation.
strip_image_tags($str)¶
-
Parameters
- $str
stringInput string
- $str
-
Returns: The input string with no image tags
-
Return type:
string
This function replaces image tags with their src values and removes tags without src. It does not sanitize HTML or escape the returned values. Use appropriate escaping when displaying the result as text.
Note
If tag replacement fails or the iteration limit is reached, any remaining <img prefixes are escaped as <img, so the result may contain escaped tag text.
Example:
<?php
$string = strip_image_tags($string);
encode_php_tags($str)¶
-
Parameters
- $str
stringInput string
- $str
-
Returns: Safely formatted string
-
Return type:
string
This is a security function that converts PHP tags to entities.
Example:
<?php
$string = encode_php_tags($string);