Home  >  Article  >  Backend Development  >  How to forward URL in PHP

How to forward URL in PHP

Guanhui
GuanhuiOriginal
2020-05-14 16:09:534541browse

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');

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;

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!

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