主页 M

php使用CURL获取302跳转后的地址实例

2015-07-12 网页编程网 网页编程网
 /*返回一个302地址*/
function  curl_post_302($url, $vars) {
      $ch = curl_init();
      curl_setopt($ch,  CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL,  $url);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch,  CURLOPT_FOLLOWLOCATION, 1); // 302 redirect
      curl_setopt($ch,  CURLOPT_POSTFIELDS, $vars);
      $data = curl_exec($ch);
      $Headers =  curl_getinfo($ch);
      curl_close($ch);
      if ($data != $Headers)
      return  $Headers["url"];
      else
      return false;
}
阅读原文
阅读 3973
123 显示电脑版