What are the potential pitfalls when dealing with GET parameters in PHP?

When dealing with GET parameters in PHP, one potential pitfall is the risk of SQL injection attacks if the parameters are directly used in database queries without proper sanitization. To prevent this, always sanitize and validate GET parameters before using them in SQL queries. Another pitfall is the possibility of XSS attacks if user input from GET parameters is echoed back to the page without proper escaping.

// Sanitize and validate GET parameters before using them in SQL queries
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
$username = isset($_GET['username']) ? filter_var($_GET['username'], FILTER_SANITIZE_STRING) : '';

// Escape user input before echoing it back to the page
echo htmlentities($_GET['search_query'], ENT_QUOTES, 'UTF-8');