$url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_USERAGENT => $user_agent,
CURLOPT_REFERER => $referrer,
CURLOPT_HTTPHEADER => $headers,
]);
// Execute request
$content = curl_exec($ch);
// Get the host and content type of the URL we were redirected to
$url_new = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
// Check for error
if ($content === false) {
// Throw exception if error found
throw new Exception(curl_error($ch));
}
// Close CURL
curl_close($ch);
// Check URL host...
if (parse_url($url_new, PHP_URL_HOST) === $domain) {
// If internal
if (!is_null($content_type)) {
// Set Content-Type header
header("Content-Type: $content_type");
}
// Set X-Robots-Tag header (so search engines don't index this page)
header("X-Robots-Tag: none");
// Output contents
echo $content;
} else {
// If external; redirect
header("Location: $url_new");
}