How can one determine if a search engine is on their website?

To determine if a search engine is on your website, you can check the user agent string of the incoming request. Search engine bots typically have unique user agent strings that can be used to identify them. You can then use this information to customize the content or behavior of your website for search engine bots.

$userAgent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($userAgent, 'Googlebot') !== false || strpos($userAgent, 'bingbot') !== false) {
    // Code to customize content or behavior for search engine bots
    echo "This is a search engine bot";
} else {
    // Code for regular website visitors
    echo "This is a regular visitor";
}