php短域名转换为实际域名函数

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

$url = "http://sinaurl.cn/hbdsU5";
echo unshorten($url);
function unshorten($url) {
$url = trim($url);
$headers = get_headers($url);
$location = $url;
$short = false;
foreach($headers as $head) {
if($head=="HTTP/1.1 302 Found") $short = true;
if($short && startwith($head,"Location: ")) {
$location = substr($head,10);
}
}
return $location;
}
function startwith($Haystack, $Needle){
return strpos($Haystack, $Needle) === 0;
}

相关文章

PHP简单开启curl的方法(测试可行) 原创

PHP简单开启curl的方法(测试可行) 原创

本文讲述了PHP简单开启curl的方法。分享给大家供大家参考,具体如下: 一、问题: windows主机出现“Call to undefined function curl_init”错...

PHP中的浅复制与深复制的实例详解

PHP中的浅复制与深复制的实例详解 前言: 最近温习了一下Design Pattern方面的知识,在看到Prototype Pattern这一设计模式时,注意到其中涉及到一个浅复制与深复...

php后台程序与Javascript的两种交互方式

方法一:通过Cookie交互。 一共是三个文件,分别为:index.htm,action.php,main.htm 原理为前台页面main.htm和后台action.php通过页面框架...

高级php注入方法集锦第1/2页

'%23  ' and passWord='mypass  id=-1 union select 1,1,1&nbs...

一致性哈希算法以及其PHP实现详细解析

一致性哈希算法以及其PHP实现详细解析

在做服务器负载均衡时候可供选择的负载均衡的算法有很多,包括:  轮循算法(Round Robin)、哈希算法(HASH)、最少连接算法(Least Connection)、响应...