How can absolute paths be used effectively in PHP header redirection?

When using PHP header redirection, it is important to use absolute paths instead of relative paths to ensure that the redirection works correctly across different pages and directories. Absolute paths specify the full URL of the page to redirect to, starting with the protocol (http:// or https://) and the domain name. This ensures that the redirection always points to the correct location regardless of the current page's location.

// Using absolute path for header redirection
header("Location: http://www.example.com/newpage.php");
exit();