本教程操作环境:windows10系统、php8.1版、dell g3电脑
php怎么输出跳转后的url?
php获取跳转后的网址,使用curl
方法1:
$url = 'http://www.baidu.com/link?url=77i2gjqjj4zbbpc8ydf8xdhiqdsn1jzjfwshheosnd85pkv8xil-rckpq8_kjgknnq';$ch = curl_init();curl_setopt($ch, curlopt_url, $url);curl_setopt($ch, curlopt_nobody, 1);// 不需要页面内容curl_setopt($ch, curlopt_returntransfer, 1);// 不直接输出curl_setopt($ch, curlopt_followlocation, 1);// 返回最后的locationcurl_setopt($ch, curlopt_customrequest, 'get');//有时需要这个功能curl_setopt($ch, curlopt_maxredirs, 3);//限定只能抓取跳转3次以内的网址curl_exec($ch);$info = curl_getinfo($ch,curlinfo_effective_url);curl_close($ch);echo $info;
方法2:
$ch= curl_init("http://www.baidu.com");curl_setopt($ch, curlopt_followlocation, 1);curl_setopt($ch, curlopt_autoreferer, 1);curl_setopt($ch, curlopt_nobody, 1);curl_setopt($ch, curlopt_returntransfer, 1);curl_setopt($ch, curlopt_header, 1);curl_setopt($ch, curlopt_customrequest, 'get');//有时需要这个功能curl_exec($ch);$aaa = curl_getinfo($ch, curlinfo_effective_url);curl_close($ch);echo $aaa;
推荐学习:《php视频教程》
以上就是php怎么输出跳转后的url的详细内容。
