What are the key server variables in PHP, such as $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'], used for in URL manipulation?

Server variables such as $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] are used in PHP for URL manipulation. These variables provide information about the server environment and the current request, allowing developers to dynamically generate URLs, redirect users, or handle different parts of the URL.

// Example usage of $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] for URL manipulation
$base_url = 'http://' . $_SERVER['HTTP_HOST']; // Get the base URL
$current_url = $base_url . $_SERVER['REQUEST_URI']; // Get the current URL

// Redirect to a different page
header('Location: ' . $base_url . '/new-page.php');

// Generate a dynamic link
echo '<a href="' . $base_url . '/some-page.php">Link</a>';