php获取网页301,302后的真实地址,支持多重跳转

function getrealurl($url){
    $realurl = $url;
    try { $headers = get_headers($realurl, true); if(isset($headers['Location'])){ if(is_array($headers['Location'])){ $location = ''; for($i=count($headers['Location']); $i>0; $i--){ $location = $headers['Location'][$i-1] . $location; if (preg_match("/^(http|https)\:\/\//i", $location)) { break; } } $realurl = $location; }else{ if (!preg_match("/^(http|https)\:\/\//i", $headers['Location'])) { $realurl .= $headers['Location']; } } } } catch (Exception $e) { } return $realurl; }

 推荐:微信怎么批量删除聊天记录,彻底删除聊天记录只需这三种方法

匿名社交app有哪些,10个最火社交软件排行榜

自己建网站需要多少钱,搭建网站的基础流程分享

微信怎么恢复删除的好友,微信误删好友找回方法

猜你喜欢

转载自www.cnblogs.com/vwvwvwgwg/p/13170974.html