PHP使用CURL获取302跳转后的地址实例_PHP教程
程序员文章站
2024-01-25 12:29:28
...
直接上代码:
/*返回一个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;
}
复制代码 代码如下:
/*返回一个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跳转地址了.
上一篇: 关于php做社区网站的安全性_PHP