Skip to content

Instantly share code, notes, and snippets.

@OnkelTem
Created September 3, 2014 15:55
Show Gist options
  • Save OnkelTem/a426c0759280b9634642 to your computer and use it in GitHub Desktop.
Save OnkelTem/a426c0759280b9634642 to your computer and use it in GitHub Desktop.
<?php
$url_a = parse_url($base_url . drupal_encode_path($url));
$fp = fsockopen($url_a['host'], 80, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET $url_a[path] HTTP/1.1\r\n";
$out .= "Host: $url_a[host]\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$s = fgets($fp, 128);
if (strpos($s, 'Content-Type') === 0) {
$result = explode(';', substr($s, 13));
$content_type['mime'] = trim(array_shift($result));
foreach($result as $chunk) {
$chunk_a = explode('=', $chunk);
$content_type[$chunk_a[0]] = trim($chunk_a[1]);
}
break;
}
}
fclose($fp);
}
$content_types[$url] = $content_type;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment