2

如果 bit.ly 除了简单的Location:标头来重定向用户,还有什么想法吗?

Facebook 能够在使用bit.ly链接时解析有关最终目的地的信息,但不能解析我http://guubo.com/aaaaab使用简单Location:标题的项目链接。

我检查了 bit.ly 标题,它们看起来很普通。

4

2 回答 2

4

我进一步调查了它。从命令行尝试以下操作

curl -D headers.txt http://bit.ly/4m1AUx

然后您可以查看 的内容headers.txt,看起来像

HTTP/1.1 301 Moved
Server: nginx
Date: Sat, 28 May 2011 13:18:21 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: _bit=4de0f61d-001f7-008b9-d8ac8fa8;domain=.bit.ly;expires=Thu Nov 24 08:18:21 2011;path=/; HttpOnly
Cache-control: private; max-age=90
Location: http://slashdot.org/
MIME-Version: 1.0
Content-Length: 112

所以,不,他们正在执行正常的 301 重定向。如果需要,您可以使用PHP 的 curl 绑定在您的 PHP 代码中进行相同的检查,以获取标题以找出真实站点。

于 2011-05-28T13:20:29.960 回答
0

https://stackoverflow.com/a/41680608/7426396

我实现了获取纯文本文件的每一行,每行有一个缩短的 url,相应的重定向 url:

<?php
// input: textfile with one bitly shortened url per line
$plain_urls = file_get_contents('in.txt');
$bitly_urls = explode("\r\n", $plain_urls);

// output: where should we write
$w_out = fopen("out.csv", "a+") or die("Unable to open file!");

foreach($bitly_urls as $bitly_url) {
  $c = curl_init($bitly_url);
  curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36');
  curl_setopt($c, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($c, CURLOPT_HEADER, 1);
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 20);
  // curl_setopt($c, CURLOPT_PROXY, 'localhost:9150');
  // curl_setopt($c, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  $r = curl_exec($c);

  // get the redirect url:
  $redirect_url = curl_getinfo($c)['redirect_url'];

  // write output as csv
  $out = '"'.$bitly_url.'";"'.$redirect_url.'"'."\n";
  fwrite($w_out, $out);
}
fclose($w_out);

玩得开心,享受!密码

于 2017-01-16T16:32:45.843 回答