在 php 中使用 curl 跟踪重定向 [英] follow redirects with curl in php

查看:36
本文介绍了在 php 中使用 curl 跟踪重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用 cURL 我可以看到目标 URL,将 cURL 指向具有 CURLOPT_FOLLOWLOCATION = true 的 URL.

I know that using cURL i can see the destination URL, pointing cURL to URL having CURLOPT_FOLLOWLOCATION = true.

示例:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "www.example1.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
$result = curl_exec($ch);
$info = curl_getinfo($ch); //Some information on the fetch
curl_close($ch);

$info 将包含最终目的地的 url,可以是 www.example2.com.我希望我的上述理解是正确的.如果没有,请告诉我!

$info will have the url of the final destination which can be www.example2.com. I hope my above understanding is correct. Please let me know if not!.

我的主要问题是,所有类型的重定向 cURL 都能够知道什么?Apache 重定向、javascript 重定向、表单提交重定向、元刷新重定向!?

My main question is, what all type of redirection cURL will be able to know? Apache redirect, javascript redirects, form submition redirects, meta-refresh redirects!?

更新感谢您的回答@ceejayoz 和@Josso.那么有没有一种方法可以让我通过 php 以编程方式跟踪所有重定向?

update Thanks for your answeres @ceejayoz and @Josso. So is there a way by which I can follow all the redirect programatically through php?

推荐答案

cURL 不会跟随 JS 或元标记重定向.

cURL will not follow JS or meta tag redirects.

这篇关于在 php 中使用 curl 跟踪重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆