It's sent as an HTTP header:
function dnt_enabled()
{
return (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] == 1);
}
if dnt_enabled() {
// do stuff...
}
Or, if you're using PHP 7:
function dnt_enabled(): bool
{
return (bool)$_SERVER['HTTP_DNT'] ?? false;
}