Skip to content
PHP Logo

How can PHP developers ensure compatibility with users who have JavaScript disabled when using anchor links?

When using anchor links in PHP, developers can ensure compatibility with users who have JavaScript disabled by adding a fallback mechanism. This can be achieved by checking if JavaScript is enabled, and if not, redirecting users to the desired section of the page using PHP header redirection.

php
<?php
if(isset($_GET['section'])) {
    $section = $_GET['section'];
    header("Location: index.php#$section");
    exit;
}
?>