What are some common pitfalls to avoid when passing parameters in URLs for PHP pages?

One common pitfall to avoid when passing parameters in URLs for PHP pages is not properly sanitizing and validating user input. This can lead to security vulnerabilities such as SQL injection attacks. To solve this issue, always sanitize and validate user input before using it in your PHP code.

// Example of sanitizing and validating user input in PHP
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; // Cast the input to integer
if ($id <= 0) {
    // Handle invalid input, such as redirecting to an error page
    header("Location: error.php");
    exit();
}

// Use the sanitized and validated input in your PHP code
$query = "SELECT * FROM users WHERE id = $id";
// Execute the query and process the results