Skip to content

Instantly share code, notes, and snippets.

@rolandinsh
Created August 29, 2012 11:04
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolandinsh/3510701 to your computer and use it in GitHub Desktop.
Save rolandinsh/3510701 to your computer and use it in GitHub Desktop.
Do Not Track (DNT) detect with PHP code
function get_smc_dnt() {
/*
* Do Not Track for privacy.
* When this feature is enabled, webpage should exclude all tracking tools,
* like Google Analytic and advertising networks
*/
// returns TRUE if DNT is on and is equal to 1,
// returns FALSE if DNT is unset OR not equal to 1
return (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] == 1);
}
@mattbrundage
Copy link

Or, $_SERVER['HTTP_DNT'] === "1" to avoid type coercion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment