Privacy Protection by Enabling Do Not Track in PHP

Privacy Protection by Enabling Do Not Track in PHP


Google Chrome Privacy Settings

Do not track

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>)

DNT in PHP

Apache Environment settings with phpinfo
<?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';
}

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 ?>
<!-- Analytics disabled by user "Do Not Track" browser setting -->

Comments

Popular posts from this blog

A Tailwind CSS Preset for Laravel 5.5

Short and safe array iteration

PHPStorm's performance