Created
April 23, 2013 21:50
-
-
Save khal3d/5447700 to your computer and use it in GitHub Desktop.
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 | |
function retrieve_shortened_link($shortUrl){ | |
$headers = get_headers($shortUrl, 1); | |
if(is_array($headers['Location'])){ | |
return $headers['Location'][0]; | |
}else{ | |
return $headers['Location']; | |
} | |
} | |
if(isset($_POST['submit']) && !empty($_POST['shortUrl'])){ | |
$link = retrieve_shortened_link($_POST['shortUrl']); | |
echo "Original URL: <a href='$link'>$link</a><br />"; | |
} | |
?> | |
<html> | |
<head> | |
<title>PHP Function To Retrieve The Original URL From A Shortened URL</title> | |
</head> | |
<body> | |
<form method="post"> | |
<input name="shortUrl" type="text" value="http://bit.ly/aov0qc" /><input name="submit" type="submit" value="submit" /></form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment