php动态页面生成静态页面

180it 2020-11-06 PM 899℃ 0条
<?php

$url = 'https://www.xxx.com/index.php';
$path= 'index.html';
/*$contents = file_get_contents($url);
//如果出现中文乱码使用下面代码
//$getcontent = iconv(“gb2312″, “utf-8″,file_get_contents($url));
//echo $getcontent;
//echo $contents;
*/

 /*curl模拟get提交*/
// 设置请求头, 有时候需要,有时候不用,看请求网址是否有对应的要求
$header[] = "Content-type: application/x-www-form-urlencoded";
$user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36";

    //初始化

$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//在需要用户检测的网页里需要增加下面两行
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//curl_setopt($ch, CURLOPT_USERPWD, US_NAME.”:”.US_PWD);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;

$handle=fopen($path,"wb");
fwrite($handle,$contents);
fclose($handle);
echo 'ok';
?>
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php动态页面生成静态页面