How can PHP developers ensure that the extracted URL parameters are properly sanitized to prevent injection attacks?
To prevent injection attacks when extracting URL parameters in PHP, developers should sanitize the parameters by using functions like `filter_input()` or `filter_var()` with appropriate filters such as `FILTER_SANITIZE_STRING` or `FILTER_SANITIZE_NUMBER_INT`. This ensures that the input is properly sanitized and reduces the risk of injection attacks.
// Example of sanitizing URL parameters in PHP
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
$name = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING);
// Now $id and $name variables contain sanitized values that are safe to use