TypechoJoeTheme

轩宇网

搜索到 1 篇与 parse_url 的结果
2020-10-17

PHP获得跳转的真实地址实例

PHP获得跳转的真实地址实例
现在有很多的短网址应用,点击就跳转到缩短之前的网址了,那今天我们就来看一下,PHP如何获取短网址跳转之前的网址,其实也很简单,就是用php的get_headers 函数,取得Response Headers,之后慢慢分析就行了。给出具体实现方法,代码如下:<?php $header = get_headers($url, 1); if (strpos($header[0], '301') || strpos($header[0], '302')) { if (is_array($header['Location'])) { return $header['Location'][count($header['Location']) - 1]; } else { return $header['Location']; } } else { return $url; } ?>实例二,代码如下:<?php echo get_redirect_url('https://www.xysoft.cc/'); //...
2020年10月17日
4,053 阅读
0 评论