How to forward URL in PHP

Guanhui
Release: 2023-03-01 08:08:02
Original
4575 people have browsed it

How to forward URL in PHP

How to forward URL in PHP

1. Use the function "file_get_contents()" to pass in the URL. This function will forward the URL in Get the source code of the web page, and then output the source code;

//百度示例
echo file_get_contents('https://www.baidu.com');
Copy after login

2. Use PHP extension CURL to get the source code of the web page and then output it.

//百度示例
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.baidu.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
Copy after login

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to forward URL 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