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 }
  • 相关阅读:
    直接插入排序
    直接选择排序
    冒泡排序
    归并排序
    进程调度
    进程与线程
    c语言struct和c++struct的区别
    二叉搜索树、AVL平衡二叉搜索树、红黑树、多路查找树

    6-11 先序输出叶结点
  • 原文地址:https://www.cnblogs.com/liruning/p/6077036.html
Copyright © 2011-2022 走看看