Skip to content

Instantly share code, notes, and snippets.

@midoooo
Forked from marijn/unshorten.php
Last active August 29, 2015 14:24
Show Gist options
  • Save midoooo/e2534bcdf5be02728914 to your computer and use it in GitHub Desktop.
Save midoooo/e2534bcdf5be02728914 to your computer and use it in GitHub Desktop.
<?php
/**
* @link http://jonathonhill.net/2012-05-18/unshorten-urls-with-php-and-curl/
*/
function unshorten_url($url) {
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => TRUE, // the magic sauce
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYHOST => FALSE, // suppress certain SSL errors
CURLOPT_SSL_VERIFYPEER => FALSE,
));
curl_exec($ch);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment