Skip to content

Instantly share code, notes, and snippets.

@jahir07
Forked from marijn/unshorten.php
Created October 15, 2019 17:29
Show Gist options
  • Save jahir07/d275b42e984bc34e1423ff7bbe1c90bd to your computer and use it in GitHub Desktop.
Save jahir07/d275b42e984bc34e1423ff7bbe1c90bd 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment