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 }
  • 相关阅读:
    asp.net core 使用 StaticFiles 中间件 (不完整翻译)
    asp.net core 通过 TeamCity 实现持续集成笔记
    Swashbuckle for asp.net core 配置说明
    # TypeScript 中如何确保 this 的正确性
    MySql + EF6 + .Net Core
    ASP.NET Core + EF6
    数据库设计 Assignment 02
    NYOJ 8 一种排序
    NYOJ 23.取石子(一)
    邻接表(C++)
  • 原文地址:https://www.cnblogs.com/liruning/p/6077036.html
Copyright © 2011-2022 走看看