Are there any potential pitfalls to be aware of when appending variables to a header location in PHP?

When appending variables to a header location in PHP, it's important to be cautious of potential security risks such as header injection attacks. To mitigate this risk, always sanitize and validate user input before appending it to a header location. This can be done by using functions like `urlencode` to encode the data properly.

// Example of appending a variable to a header location safely
$userInput = $_GET['user_input']; // Assuming user_input is coming from user input

// Sanitize and validate user input
$safeUserInput = urlencode($userInput);

// Redirect with safe user input
header("Location: http://example.com/page.php?data=$safeUserInput");
exit();