Last active
January 27, 2020 13:16
-
-
Save ovlb/5e1603587d5040bcc14f41bd9be0f4a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// header.php | |
/** | |
* setcookie() needs to be called before the opening <html> tag | |
*/ | |
<?php | |
// Fallback if client side script fails and there is an opt out request | |
$opt_out_request = $_GET['fb-pixel-status']; | |
$wants_to_opt_out = isset($opt_out_request) && $opt_out_request === 'opt-out'; | |
// Check if the Do Not Track Header is set | |
$do_not_track = isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] === 1; | |
// Check for SSL/TLS to set the correct value in setcookie() below | |
$is_https = isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'on'; | |
if ($wants_to_opt_out || $do_not_track) { | |
setcookie('fb-pixel-status', 'opt-out', time()+86400 * 14600, '/', $is_https, true); | |
$_COOKIE['fb-pixel-status'] = 'opt-out'; | |
} | |
?> | |
<html> | |
<!-- site --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
actually the $is_https in the setcookie() will not work, since it's in the position of the Domain, so instead of a domain, you'll set the cookie for the domain "on".
I've removed the complete part with $is_https, and it works fine.