這篇文章主要介紹了PHP使用CURL獲取302跳轉(zhuǎn)后的地址實(shí)例,需要的朋友可以參考下
直接上代碼:
代碼如下:
/*返回一個(gè)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;
}
上面的這個(gè)curl_post_302 函數(shù)可以直接取到302跳轉(zhuǎn)地址了.
更多信息請查看IT技術(shù)專欄