как конвертировать короткие URL Google обратно в исходный URL

У меня есть несколько коротких URL-адресов, таких как http://goo.gl/fbsfS. Как я могу получить оригинальные URL-адреса из таких коротких URL-адресов, используя Ow.ly , Bit.ly а также goo.gl .если у кого-то есть такие скрипты для php, то помогите плз. Благодарю.

2

Решение

Поскольку службы URL-сокращений в основном представляют собой простые перенаправители, они используют заголовок местоположения сказать браузеру, куда идти.

Вы можете использовать собственный PHP get_headers () Функция для получения соответствующего заголовка:

$headers = get_headers('http://goo.gl/fbsfS' , true);
echo $headers['Location'];
4

Другие решения

Попробуй это

<?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
?>
2

Вы можете использовать curl функции за это:

// 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);
0

Для всех сервисов есть API, который вы можете использовать.

-2