zoukankan      html  css  js  c++  java
  • PHP如何通过URL访问,获得新的URL 两种方法

    1.1

    1 $url = 'http://passport.drcloud.cn/api/logon.asp?id=1&ru=http://203.158.158.122/store/thirdLogin.php&tw=1800&sm=0&lc=2052';
    2 $newurl = getMapUrl($url);
    3 echo $newurl;
    4  
    5 function getMapUrl($url){
    6     $result = get_headers($url, true);
    7     return isset($result['Location'])? $result['Location'] : '';
    8 }

    1.2

     1 $url = 'http://passport.drcloud.cn/api/logon.asp?id=1&ru=http://203.158.158.122/store/thirdLogin.php&tw=1800&sm=0&lc=2052';
     2 $newurl = getMapUrl($url);
     3 echo $newurl;
     4 
     5 function getMapUrl($url){
     6     file_get_contents($url);
     7     $result = $http_response_header;
     8     if($result){
     9         foreach($result as $val){
    10             if(substr($val,0,10)=='Location: '){
    11                 return str_replace('Location: ','', $val);
    12             }
    13         }
    14     }
    15     return '';
    16 }

    2

     1 $url = 'http://passport.drcloud.cn/api/logon.asp?id=1&ru=http://203.158.158.122/store/thirdLogin.php&tw=1800&sm=0&lc=2052';
     2 $newurl = getHeadersNew($url);
     3 var_dump($newurl);
     4 function getHeadersNew($url){ 
     5     $ch= curl_init(); 
     6     curl_setopt($ch, CURLOPT_URL, $url); 
     7     curl_setopt($ch, CURLOPT_NOBODY, 1); 
     8     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     9     curl_setopt($ch, CURLOPT_HEADER, 1); 
    10     $f=curl_exec($ch); 
    11     curl_close($ch); 
    12     $h=explode("
    ",$f); 
    13     $r=array(); 
    14     foreach( $h as $t){ 
    15       $rr=explode(":",$t,2); 
    16       if(count($rr)==2 ){ $r[$rr[0]]=trim($rr[1]);} 
    17     } 
    18     return $r; 
    19 }
  • 相关阅读:
    字符串倒序
    字符串反转问题
    linux系统性能分析
    操作系统基础知识
    两个数组a[N],b[N],其中A[N]的各个元素值已知,现给b[i]赋值,b[i] = a[0]*a[1]*a[2]…*a[N-1]/a[i];
    用加法模拟乘法
    2015年最新中国知网CNKI免费账号直接入口
    nginx模块开发(18)—日志分析
    nginx基本配置
    三层架构和MVC
  • 原文地址:https://www.cnblogs.com/liruning/p/6077036.html
Copyright © 2011-2022 走看看