Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GET /dmsfm HTTP/1.0
- Host: tinyurl.com
- HTTP/1.0 301 Moved Permanently
- Connection: close
- X-Powered-By: PHP/5.2.6
- Location: http://en.wikipedia.org/wiki/TinyURL
- Content-type: text/html
- Content-Length: 0
- Date: Mon, 15 Sep 2008 12:29:04 GMT
- Server: TinyURL/1.6
- <?php
- $tinyurl="dmsfm";
- $fp = fsockopen("tinyurl.com", 80, $errno, $errstr, 30);
- if (!$fp) {
- echo "$errstr ($errno)<br />n";
- } else {
- $out = "GET /$tinyurl HTTP/1.0rn";
- $out .= "Host: tinyurl.comrn";
- $out .= "Connection: Closernrn";
- $response="";
- fwrite($fp, $out);
- while (!feof($fp)) {
- $response.=fgets($fp, 128);
- }
- fclose($fp);
- //now parse the Location: header out of the response
- }
- ?>
- function make_tinyurl($longurl)
- {
- return(implode('', file(
- 'http://tinyurl.com/api-create.php?url='.urlencode($longurl))));
- }
- // make an example call
- print(make_tinyurl('http://www.joelonsoftware.com/items/2008/09/15.html'));
- def resolve_tinyurl(url):
- key = md5( url.lower_case() )
- if cache.has_key(key)
- return cache[md5]
- else:
- resolved = query_tinyurl(url)
- cache[key] = resolved
- return resolved
- <?php
- function getTinyUrl($url) {
- return file_get_contents('http://tinyurl.com/api-create.php?url='.$url);
- }
- ?>
- $tinyurl = 'http://tinyurl.com/3fvbx8';
- $context = stream_context_create(array('http' => array('method' => 'HEAD')));
- $response = file_get_contents($tinyurl, null, $context);
- $location = '';
- foreach ($http_response_header as $header) {
- if (strpos($header, 'Location:') === 0) {
- $location = trim(strrchr($header, ' '));
- break;
- }
- }
- echo $location;
- // http://www.pingdom.com/reports/vb1395a6sww3/check_overview/?name=twitter.com%2Fhome
- function doShortURLDecode($url) {
- $ch = @curl_init($url);
- @curl_setopt($ch, CURLOPT_HEADER, TRUE);
- @curl_setopt($ch, CURLOPT_NOBODY, TRUE);
- @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
- @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $response = @curl_exec($ch);
- preg_match('/Location: (.*)n/', $response, $a);
- if (!isset($a[1])) return $url;
- return $a[1];
- }
Add Comment
Please, Sign In to add comment