PHP中怎么进行URL转发

来自:互联网
时间:2020-05-14
阅读:
免费资源网 - https://freexyz.cn/

PHP中怎么进行URL转发

1、使用函数“file_get_contents()”将URL传入,该函数会将URL中的网页源代码进行获取,然后将源代码输出即可;

//百度示例
echo file_get_contents('https://www.bAIdu.com');

2、使用PHP扩展CURL将网页源代码获取再输出即可。

//百度示例
$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;
免费资源网 - https://freexyz.cn/
返回顶部
顶部