Skip to content

Instantly share code, notes, and snippets.

@srokatonie
Created August 6, 2020 11:31
Show Gist options
  • Save srokatonie/bda12a1ff046e253a04c966dec63bae8 to your computer and use it in GitHub Desktop.
Save srokatonie/bda12a1ff046e253a04c966dec63bae8 to your computer and use it in GitHub Desktop.
$redirectFacebook = false;
// Fix stupid Facebook button restriction by checking the referer link
// and if comes from FB, go to specifified
if ($redirectFacebook) {
$host = "https://domain.com/";
$uri = "final-uri/";
$location = "Location: " . $host . $uri;
$refererUrl = strtolower($_SERVER['HTTP_REFERER']);
$refererDomain = strpos($refererUrl, 'facebook');
$whatINeed = explode('/', $_SERVER['REQUEST_URI']);
$whatINeed = $whatINeed[1];
if ($refererDomain !== false && $whatINeed != $uri) { // prevent circular thing
if (isset($_GET["fbclid"])) {
echo "Redirect to " . $_GET["fbclid"];
$location = $location . "?fbclid=" . $_GET["fbclid"];
}
header($location, true, 302);
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment