Created
October 16, 2012 20:52
-
-
Save marijn/3901938 to your computer and use it in GitHub Desktop.
Unshorten URLS with PHP and CURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This is not mine: http://jonathonhill.net/2012-05-18/unshorten-urls-with-php-and-curl/