Home > php教程 > PHP源码 > body text

php curl 取得要跳转的url

PHP中文网
Release: 2016-05-26 08:21:17
Original
1361 people have browsed it

取得要跳转的url,方便下一步操作。有时候我们不需要跳转的内容,而更需要跳转的网址就可以使用它了

//获得要跳转的网址,进行下一步操作
function  curl_post_302($url,$data=null) {

	$ch = curl_init();
	curl_setopt($ch,  CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL,  $url);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch,  CURLOPT_POSTFIELDS, $vars);
	curl_setopt($ch,  CURLOPT_FOLLOWLOCATION, 1); // 获取转向后的内容          
	$data = curl_exec($ch);
	$Headers =  curl_getinfo($ch);		 
	curl_close($ch);
	if ($data != $Headers){		 
		return $Headers["url"];		  
	}else{
		return false;
	}

}
echo curl_post_302($302url);//得到要跳转的地址
Copy after login

                   

 以上就是php curl 取得要跳转的url的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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