What are common pitfalls to avoid when using PHP to manage website navigation and user redirection?

One common pitfall to avoid when using PHP to manage website navigation and user redirection is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate this risk, always validate and sanitize user input before using it in any navigation or redirection logic.

// Sanitize user input before using it for redirection
$user_input = $_GET['page'];
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);

// Redirect user to the sanitized page
header("Location: $sanitized_input");
exit();