Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);

This comment has been minimized.

Copy link

@mattbrundage mattbrundage commented Mar 1, 2018

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