Are there best practices for distinguishing between legitimate users and web crawlers like Googlebot in PHP forums?

When distinguishing between legitimate users and web crawlers like Googlebot in PHP forums, one common approach is to check the User-Agent header in the HTTP request. Legitimate users typically have a browser User-Agent, while web crawlers often have specific identifiers like "Googlebot". By checking the User-Agent header, you can differentiate between the two and implement specific actions or restrictions accordingly.

$userAgent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($userAgent, 'Googlebot') !== false) {
    // This is Googlebot, take appropriate action
    echo "Hello Googlebot!";
} else {
    // This is a legitimate user, continue with normal forum operations
    echo "Hello User!";
}