3v4l.org

run code in 500+ PHP versions simultaneously
<?php $default = 'hacs.xyz'; $url = ltrim($_GET['u'] ?? $_SERVER['QUERY_STRING'] ?? $_SERVER['REQUEST_URI'] ?? '', '/') ?: $default; $url = preg_replace('#^index\.php/#i', '', $url); if (in_array($url, ['', 'favicon.ico', 'opensearch.xml'])) { exit(); } if (!preg_match('/https?:/i', $url)) { $url = "https://$url"; } list($body, $headers) = request($url); foreach ($headers as $k => $v) { if (in_array(strtolower($k), ['content-type', 'content-encoding'])) { header("$k: $v"); } } echo $body; function request($url) { error_log($url); $ua = $_SERVER['HTTP_USER_AGENT'] ?? 'Mozilla/5.0 Chrome/139'; $headers = ["Content-Type: $ua\r\n"]; if ($ref = $_SERVER['HTTP_REFERER'] ?? '') { $headers[] = "Referer: $ref\r\n"; } $http = [ 'method' => 'GET', 'header' => join($headers), ]; $context = stream_context_create(compact('http')); $body = file_get_contents($url, false, $context); $headers = array_reduce($http_response_header ?? [], function ($dat, $head) { $arr = explode(':', $head, 2); if (isset($arr[1])) { $dat[$arr[0]] = trim($arr[1]); } return $dat; }, []); if ($location = $headers['Location'] ?? $headers['location'] ?? null) { if (str_starts_with($location, '/')) { $schema = parse_url($url, PHP_URL_SCHEME); $host = parse_url($url, PHP_URL_HOST); $location = "$schema://$host$location"; } return request($location); } return [$body, $headers]; }

preferences:
56.62 ms | 890 KiB | 5 Q