惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
博客园 - 叶小钗
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
爱范儿
爱范儿
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
量子位
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
SecWiki News
SecWiki News
MyScale Blog
MyScale Blog
AI
AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 【当耐特】
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
有赞技术团队
有赞技术团队
W
WeLiveSecurity
Project Zero
Project Zero
T
Tor Project blog
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
IT之家
IT之家
The Hacker News
The Hacker News
腾讯CDC
Schneier on Security
Schneier on Security
N
News and Events Feed by Topic
C
Cisco Blogs
博客园 - 聂微东
Webroot Blog
Webroot Blog
Forbes - Security
Forbes - Security
M
MIT News - Artificial intelligence
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans

孟坤博客

我用 HTML 复刻了 QQ2006 | 孟坤博客 我用 HTML 复刻了 QQ2006 | 孟坤博客 小米智能家电产品使用体验 | 孟坤博客 小米智能家电产品使用体验 | 孟坤博客 【已送完】腾讯云 EdgeOne 免费计划兑换码 | 孟坤博客 【已送完】腾讯云 EdgeOne 免费计划兑换码 | 孟坤博客 PHP 从链接中提取出顶级域名 | 孟坤博客 PHP 从链接中提取出顶级域名 | 孟坤博客 愚人节整蛊代码:你屏幕上有根毛 | 孟坤博客 愚人节整蛊代码:你屏幕上有根毛 | 孟坤博客 deepin 安装小记 | 孟坤博客 deepin 安装小记 | 孟坤博客 HTML + CSS 实现一个酷炫的夜间模式切换动画 | 孟坤博客 HTML + CSS 实现一个酷炫的夜间模式切换动画 | 孟坤博客 CSS 实现新拟态(Neumorphism) UI 风格 | 孟坤博客 CSS 实现新拟态(Neumorphism) UI 风格 | 孟坤博客 CSS 绘制圣诞老人 | 孟坤博客 CSS 绘制圣诞老人 | 孟坤博客 PHP 实现“万能”的短网址还原 | 孟坤博客
PHP 实现“万能”的短网址还原 | 孟坤博客
mengkun · 2019-12-01 · via 孟坤博客

常见的短网址都是通过 301 或 302 跳转的方式实现重定向到目标网站的,因此我们可以使用 PHP 的 curl_getinfo 来取得 header 中的重定向地址,也就是短网址对应的原始网址(嗯,原理就是这么简单……[aru_49]

完整的函数代码如下:

/***
 * 万能短网址还原函数
 * @param $shortUrl 短网址
 * @return 原始网址 | 空(还原失败或非短网址)
 */
function restoreUrl($shortUrl) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $shortUrl);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0');
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_NOBODY, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 15);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
    $data = curl_exec($curl);
    $curlInfo = curl_getinfo($curl);
    curl_close($curl);
    if($curlInfo['http_code'] == 301 || $curlInfo['http_code'] == 302) {
        return $curlInfo['redirect_url'];
    }
    return '';
}

使用方法:

$shortUrl = 'https://url.cn/54VbB8h';    // 要还原的短网址
$orinalUrl = restoreUrl($shortUrl);
if($orinalUrl) {
    echo "短网址 {$shortUrl} 的还原结果:{$orinalUrl}";
} else {
    echo "短网址还原失败";
}

经过实测,该函数可以顺利实现下列短网址的还原:[aru_47]

  • https://url.cn/54VbB8h
  • http://t.cn/AiR8Qoyp
  • http://uee.me/cAhq8
  • http://rrd.me/eWCg3
  • https://sohu.gg/MSYnnHo02
  • https://dwz.cn/I5l2YWKL
  • http://1t.click/bceu
  • http://dwz.win/qMp
  • http://qq.cn.hn/e8N
  • http://tb.cn.hn/x7X
  • http://jd.cn.hn/aaK9
  • http://tinyurl.com/y5gkl3v9
  • http://u6.gg/sLaav
  • http://c7.gg/fQBWn
  • http://985.so/ejaT
  • http://new.3qtt.cn/1hqafu
  • http://dwz1.cc/DvjLsDcC
  • https://ml.mk/‌‌‌​‌​​‌​‌​‌‌​‌‌‌/
  • https://ml.mk/BvZ
  • http://suo.im/555AiB
  • https://suo.dog/msugd
  • http://sina.lt/eEyd
  • http://mrw.so/4woTLt

不过,诸如 https://m.tb.cn/h.ew5NAEA 这种在前端使用 js 跳转的短网址就无能为力了~_~

本文作者为mengkun,转载请注明。

26人点赞

打赏