[ 'verify_peer' => true, 'verify_peer_name' => true, ], ]; $context = stream_context_create($contextOptions); // Try to get headers first to check if file exists and wasn't redirected $headers = @get_headers($jsFile, 1); // 1 to get headers as array if ($headers === false) { return "The file $livejsFile can't be loaded (connection error)."; } // Check for redirects $statusLine = $headers[0]; if (strpos($statusLine, '301') !== false || strpos($statusLine, '302') !== false) { return "The file $livejsFile was redirected - this might indicate the file doesn't exist."; } // Check if we got 200 OK if (strpos($statusLine, '200') === false) { return "The file $livejsFile can't be loaded (HTTP error: $statusLine)."; } // Check content type $contentType = isset($headers['Content-Type']) ? $headers['Content-Type'] : ''; if (is_array($contentType)) { $contentType = end($contentType); // get last content-type in case of redirects } if (stripos($contentType, 'javascript') === false && stripos($contentType, 'text/plain') === false) { return "The file $livejsFile doesn't appear to be a JavaScript file (got $contentType)."; } // get the file $fileContent = @file_get_contents($jsFile, false, $context); if ($fileContent !== false) { // Quick validation of content $firstLine = strtolower(trim(substr($fileContent, 0, 100))); if (strpos($firstLine, '') !== false || strpos($firstLine, '