How can browser compatibility affect the functionality of anchors in PHP header redirects?
Browser compatibility can affect the functionality of anchors in PHP header redirects because some browsers may not properly handle anchors in the Location header. To ensure consistent behavior across browsers, it's recommended to avoid using anchors in header redirects and instead use JavaScript to scroll to a specific section of a page after the redirect.
<?php
// Redirect without anchor
header('Location: http://example.com/newpage.php');
// Redirect with JavaScript to scroll to a specific section
echo '<script>window.location.href = "http://example.com/newpage.php#section";</script>';
?>