diff --git a/src/MD_STD.php b/src/MD_STD.php index 6c8517b..d81ea69 100644 --- a/src/MD_STD.php +++ b/src/MD_STD.php @@ -428,6 +428,12 @@ final class MD_STD { } else { $lang = self::lang_getfrombrowser($allowed_langs, $default_lang, "", false); + + // If the user is a bot or has no user agent at all or one of curl's, + // setting a cookie usually makes little sense. + // On the other hand, setting the cookie prevents effective caching. + if (empty($_SERVER['HTTP_USER_AGENT']) || substr($_SERVER['HTTP_USER_AGENT'], 0, 5) === 'curl/') return $lang; + if (!setcookie('__Host-lang', $lang, $cookie_options)) { throw new Exception("Failed to set language"); }