Created
July 26, 2024 11:42
Revisions
-
dvygolov created this gist
Jul 26, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ <?php class ShakesRedirectCorrector { private function get_headers($url): array { $ch = curl_init(); $headers = []; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$headers) { $len = strlen($header); $header = explode(':', $header, 2); if (count($header) < 2) // ignore invalid headers return $len; $headers[strtolower(trim($header[0]))][] = trim($header[1]); return $len; } ); $data = curl_exec($ch); return $headers; } public function get_https_redirect(): string { $queries = array(); parse_str($_SERVER['QUERY_STRING'], $queries); $url = "http://streamshakes.com/".$queries['q']; $prefix= "http://"; $headers = $this->get_headers($url); $location = $headers['location'][0]; if (strpos($location, $prefix) === 0) $location = "https://" . str_replace($prefix, "", $location); return $location; } } $r = new ShakesRedirectCorrector(); $location = $r->get_https_redirect(); header("Location: {$location}"); ?>