PHP 通用 url 缩短解码器库
是否有任何类型的 PHP 库可以在不发出 CURL 请求的情况下解码tinyurl、Goo.gl、bit.ly 和其他 url 缩短的 url?
Is there any kind of library for PHP which can decode tinyurl, Goo.gl, bit.ly and other url shortened urls without making CURL requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过 URL 缩短,创建的哈希值与被缩短的 URL 无关,而是一个简单优雅的内部数据库标识符。
检索 URL 位置的唯一方法是要求链接缩短站点处理请求,然后捕获响应数据,唯一的方法是通过网络连接到该站点。
除非该位置的哈希值是长 URL 的可逆哈希值,否则没有其他方法可以做到这一点。
With URL shortening the hashes created have no relevancy to the URL being shortened but mealy a simple elegant internal database identifier.
The only way to retrieve the URL location is to ask the link shortening site to process the request and then catch the response data, the only way to do that is with networking to that site.
Unless the hash for the location is a reversible hash of long URL, there is no other way to do it.
至少 bit.ly 和 TinyURL 仅使用 HTTP 重定向。
所以你可以只获取Location响应头。例如,您可以使用 PEAR
HTTP_Request2
。我不知道是否所有服务都使用这种方法,但它是最明显的使用方法......我不知道为什么你不想使用curl。您是在谈论特定库中的curl 还是一般网络库中的curl?从网页获取信息而不连接到它对我来说似乎相当无意义:-)
这是不使用库的“最少的努力快速'n dirty”方法......(你可以
grep 用于
Location
标头)...您可以使用套接字完成相同的操作...At least bit.ly and TinyURL just uses HTTP redirects.
So you can just get the Location response header. You can use PEAR
HTTP_Request2
for example. I don't know if all services use this method, but it is the most obvious one to use...I'm not sure why you don't want to use curl. Are you talking about curl in specific or networking libraries in general? Getting information from a webpage without connecting to it seems rather non-sensical to me :-)
This is the "minimal effort quick 'n dirty" method that doesn't use a library... (You can
grep
for theLocation
header) ... You can accomplish the same using sockets...不,这是不可能的。我创建了一个适用于大多数主机的小功能包。
它与curl一起使用,但如果没有CURL/network则无法做到这一点
No. It isn't possible. I created small pack of function which works on most hosts.
it is with curl but it isn't possible to do it without CURL/network
除非您拥有自己的 Shortner 服务数据库副本,否则您必须提出某种请求。如果不是缩短的 url 本身,则可以是服务的某些 API。嗯,实际上,我想,请求短 URL 并获取重定向标头在技术上是一个 API。
所以我会说卷曲它。不要遵循重定向,并确保设置 cURL 以返回标头(因为没有其他内容)。您正在寻找
Location: ....
标头Unless you have your own copy of the shortner service's database, you have to make some kind of request. If not to the shortened url itself, then to some API of the service. Well, actually, requesting the short url and getting the redirection header is technically an API, I suppose.
So I'd say cURL it. Don't follow redirects, and make sure you set cURL to return the headers (because there's nothing else). You're looking for the
Location: ....
header