Home > php教程 > php手册 > PHP使用CURL获取302跳转后的地址实例

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

WBOY
Release: 2016-06-13 09:36:05
Original
1835 people have browsed it

直接上代码:

复制代码 代码如下:


      /*返回一个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;

     }

上面的这个curl_post_302 函数可以直接取到302跳转地址了.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template