Skip to content

Instantly share code, notes, and snippets.

@bjrnqprs
Created September 7, 2013 15:43
Show Gist options
  • Save bjrnqprs/6476662 to your computer and use it in GitHub Desktop.
Save bjrnqprs/6476662 to your computer and use it in GitHub Desktop.
A simple function to resolve a shortened url to its original. Uses PHP+cURL.
#! /usr/bin/env php
<?php
// Resolve Short URL
function resolveShortURL($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$yy = curl_exec($ch);
$endUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return $endUrl;
}
if($argc === 2) {
echo resolveShortURL($argv[1])."\n";
} else {
echo "ERROR: Missing first parameter: URL.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment