Last active
February 5, 2019 23:10
-
-
Save adamcrampton/f3425f042e53c729dbb3c263e1c63b70 to your computer and use it in GitHub Desktop.
Return the forwarded URL using cURL - useful for link shorteners etc
This file contains hidden or 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 | |
function returnRedirectedUrl($url) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$a = curl_exec($ch); | |
if(preg_match('#Location: (.*)#', $a, $r)) | |
$permalink = trim($r[1]); | |
return $permalink; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment