如何将 Google short URLs 转换回原来的 URL?

How to convert Google short URLs back to its original URL?

我有一些短网址。我怎样才能从他们那里得到原始网址?

所有服务都有一个 API,您可以使用它。

试试这个

<?php 

$url="http://goo.gl/fbsfS";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$a = curl_exec($ch); // $a will contain all headers

$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // This is what you need, it will return you the last effective URL

echo $url; // Redirected url
?>

您可以为此使用 curl functions

// The short url to expand
$url = 'http://goo.gl/fbsfS';

// Prepare a request for the given URL
$curl = curl_init($url);

// Set the needed options:
curl_setopt_array($curl, array(
    CURLOPT_NOBODY => TRUE,            // Don't ask for a body, we only need the headers
    CURLOPT_FOLLOWLOCATION => FALSE,   // Don't follow the 'Location:' header, if any
));

// Send the request (you should check the returned value for errors)
curl_exec($curl);

// Get information about the 'Location:' header (if any)
$location = curl_getinfo($curl, CURLINFO_REDIRECT_URL);

// This should print:
//    http://translate.google.com.ar/translate?hl=es&sl=en&u=http://goo.gl/lw9sU
echo($location);

由于 URL-shortener-services 大多是简单的重定向器,它们使用 location header 告诉浏览器去哪里。

你可以使用PHP自带的get_headers()函数得到合适的header:

$headers = get_headers('http://shorten.ed/fbsfS' , true);
echo $headers['Location'];