Home >Backend Development >PHP Problem >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!