How can PHP be used to automatically redirect to a dynamically generated URL?

To automatically redirect to a dynamically generated URL in PHP, you can use the header() function along with concatenating the dynamic URL within the location header. This will send a raw HTTP header to the browser, instructing it to redirect to the specified URL.

<?php
// Generate the dynamic URL
$dynamic_url = "https://example.com/page.php?id=123";

// Redirect to the dynamically generated URL
header("Location: " . $dynamic_url);
exit;
?>