Skip to content

Instantly share code, notes, and snippets.

@marijn
Created October 16, 2012 20:52
Show Gist options
  • Save marijn/3901938 to your computer and use it in GitHub Desktop.
Save marijn/3901938 to your computer and use it in GitHub Desktop.
Unshorten URLS with PHP and CURL
<?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;
}
@marijn
Copy link
Author

marijn commented Oct 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment