How does the PHP header function interact with external URLs and potential referrer issues?

When using the PHP header function to redirect to an external URL, there can be potential referrer issues where the original site's URL is not passed along. To solve this, you can use the "header" function with the "Location" parameter to redirect to the external URL and include the "Referer" header to pass the original site's URL.

<?php
$external_url = 'https://www.externalurl.com';
$referer_url = $_SERVER['HTTP_REFERER'];

header("Location: $external_url");
header("Referer: $referer_url");
exit();
?>