Skip to content

Instantly share code, notes, and snippets.

@DragonBe
Created October 20, 2017 08:34
Show Gist options
  • Save DragonBe/b21a8d44990001858e777e2f4415050a to your computer and use it in GitHub Desktop.
Save DragonBe/b21a8d44990001858e777e2f4415050a to your computer and use it in GitHub Desktop.
Functionality to verify if "Do not track" is set in the browser configuration.
<?php
/**
* Functionality to verify if "Do not track" is set
* in the browser configuration.
*/
if (array_key_exists('HTTP_DNT', $_SERVER) && (1 === (int) $_SERVER['HTTP_DNT'])) {
echo 'Do not track me enabled';
} else {
echo 'Do not track me disabled';
}
@DragonBe
Copy link
Author

DragonBe commented Oct 20, 2017

Functionality to verify if "Do not track" is set in the browser configuration for Google Analytics.

<?php if (array_key_exists('HTTP_DNT', $_SERVER) || (1 !== (int) $_SERVER['HTTP_DNT'])): ?>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');
</script>
<?php endif ?>

@DragonBe
Copy link
Author

An example request header:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en;q=0.8,en-US;q=0.6,nl;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
DNT:1
Host:www.in2it.be
Referer:https://www.in2it.be/
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (<script>alert('You should filter input');</script>)

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