Created
December 16, 2022 04:27
-
-
Save sirilyan/8b984f8bf1fd65323d85db4cd239195d to your computer and use it in GitHub Desktop.
A perfectly normal redirector
This file contains 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 | |
$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