Home > Backend Development > PHP Problem > How to output the url after jump in php

How to output the url after jump in php

藏色散人
Release: 2023-03-17 20:08:01
Original
2040 people have browsed it

How to output the URL after the jump in php: 1. Get the URL after the jump through "curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);"; 2. Through "curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET' );" just get and use the echo output.

How to output the url after jump in php

The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

How to output php after the jump url?

php gets the URL after the jump, use curl

Method 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);// 返回最后的Location
curl_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;
Copy after login

Method 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;
Copy after login

Recommended learning:《PHP video tutorial

The above is the detailed content of How to output the url after jump in php. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template