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

How to output the url after jump in php

藏色散人
藏色散人Original
2023-01-19 09:16:301973browse

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;

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;

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!

Statement:
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