How can a PHP page be made visible only to a specific UserAgent?

To make a PHP page visible only to a specific UserAgent, you can check the UserAgent string in the HTTP request and restrict access based on that. This can be useful for serving different content or restricting access to certain types of browsers or bots.

<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];

// Check if the UserAgent matches the specific one you want to allow
if($userAgent === 'SpecificUserAgent') {
    // Page content visible only to the specific UserAgent
    echo "Welcome SpecificUserAgent!";
} else {
    // Redirect or show an error message for other UserAgents
    header("HTTP/1.1 403 Forbidden");
    echo "Access Forbidden";
}
?>