What are the potential security risks of using $_GET to pass CSS file names in PHP?
Using $_GET to pass CSS file names in PHP can pose security risks such as allowing for directory traversal attacks or injection of malicious code. To mitigate these risks, it is recommended to validate and sanitize the input before using it to include the CSS file.
$css_file = isset($_GET['css_file']) ? basename($_GET['css_file']) : 'default.css';
$css_file_path = 'css/' . $css_file;
// Validate and sanitize the input
if (!file_exists($css_file_path)) {
$css_file = 'default.css';
}
// Include the CSS file
echo '<link rel="stylesheet" type="text/css" href="' . $css_file_path . '">';
Keywords
Related Questions
- In PHP, what considerations should be made when choosing between storing image filenames in a database versus using PHP functions to dynamically determine the image file to display?
- How do Marker-Interfaces differ from regular interfaces in PHP and what advantages do they offer in coding?
- What is the significance of the error message "mysql_fetch_array(): supplied argument is not a valid MySQL result resource" in PHP?