Skip to content

Instantly share code, notes, and snippets.

@sirilyan
Created December 16, 2022 04: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 sirilyan/8b984f8bf1fd65323d85db4cd239195d to your computer and use it in GitHub Desktop.
Save sirilyan/8b984f8bf1fd65323d85db4cd239195d to your computer and use it in GitHub Desktop.
A perfectly normal redirector
<?php
$realMappings = [
'/aa124e' => 'https://www.ctv.ca/'
];
$hiddenMappings = [
'/aa124e' => 'https://www.cbc.ca/'
];
$hideFrom = [
'twitter' => '/Twitterbot/'
];
$safePerson = true;
$userAgent = $_SERVER['HTTP_USER_AGENT'];
foreach ($hideFrom as $source => $regex) {
if (preg_match($regex, $userAgent)) {
$safePerson = false;
break;
}
}
$pathInfo = $_SERVER['PATH_INFO'];
if (!array_key_exists($pathInfo, $realMappings)) {
http_response_code(404);
exit(1);
}
$url = $safePerson ? $realMappings[$pathInfo] : $hiddenMappings[$pathInfo];
http_response_code(301);
header('Location: ' . $url);
header('Content-Type: text/plain');
echo "Bye";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment