Created
November 3, 2024 14:27
-
-
Save jarkko-hautakorpi/d24a1bbd669fac7116caa50530be6097 to your computer and use it in GitHub Desktop.
googleadservices.com capture and redirect to bypass ads tracking
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 | |
// Use the Redirector Chrome plugin to redirect to your local site. | |
// Catch AD URLs like https://www.googleadservices.com/pagead/aclk?sa=L&ai=CPeysfenknZ5HpCCI2yiM0PtbaegA... | |
// Check if 'adurl' parameter exists in the URL query string | |
if (isset($_GET['adurl'])) { | |
$adUrl = $_GET['adurl']; | |
// Basic validation to ensure it's a HTTP/HTTPS URL | |
if (preg_match('/^(http|https):\/\//', $adUrl)) { | |
// Redirect browser to the extracted ad URL | |
header('Location: ' . $adUrl); | |
exit; | |
} else { | |
// Fallback: Google Search for invalid adurl | |
http_response_code(302); // Found (for redirects) | |
$lastParam = basename(parse_url($adUrl, PHP_URL_PATH)); | |
$searchQuery = urlencode($lastParam); | |
header('Location: https://www.google.com/search?q=' . $searchQuery); | |
exit; | |
} | |
} else { | |
// No 'adurl' parameter: Google Search for last URL parameter | |
http_response_code(302); // Found (for redirects) | |
$queryParams = array_slice($_GET, -1); // Get the last query parameter | |
$lastKey = key($queryParams); | |
$searchQuery = urlencode($lastKey . ':' . $queryParams[$lastKey]); | |
header('Location: https://www.google.com/search?q=' . $searchQuery); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment