How can you securely retrieve and process user input from URLs in PHP?
When retrieving user input from URLs in PHP, it is important to validate and sanitize the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One way to securely retrieve and process user input from URLs is by using the filter_input() function in PHP. This function allows you to specify the type of input you expect (e.g., integer, string) and automatically sanitizes the input for you.
// Retrieve and sanitize user input from URL
$user_input = filter_input(INPUT_GET, 'user_input', FILTER_SANITIZE_STRING);
// Process the sanitized user input
if ($user_input) {
// Process the user input
echo "User input: " . $user_input;
} else {
// Handle invalid input
echo "Invalid input";
}