Created
March 14, 2013 08:02
-
-
Save venj/5159660 to your computer and use it in GitHub Desktop.
Expand short url with php + curl.
via http://nullpointer.ph/questions/2761/using-php-how-can-you-get-the-long-url-equivalent-of-a-short-url
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 | |
if ($_GET["shorturl"]) { | |
$short_url = $_GET["shorturl"]; | |
$ch = curl_init($short_url); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); | |
curl_setopt($ch, CURLOPT_NOBODY, TRUE); | |
curl_exec($ch); | |
echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | |
/* | |
echo "<p>" . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) . "</p>"; | |
$info = curl_getinfo($ch); | |
echo "<p>" . $info["redirect_count"] . "</p>"; | |
*/ | |
} | |
else { | |
$html =<<<END | |
<form action="/url.php" method="get" accept-charset="utf-8"> | |
<p><input type="text" name="shorturl" value=""> | |
<input type="submit" value="Expand"></p> | |
</form> | |
END; | |
echo $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment