重定向页面后如何保存HTML文件

时间:2014-06-22 09:28:12

标签: javascript php html redirect domdocument

我正在尝试在重定向到新网址后保存HTML页面。重定向工作正常,但似乎在重定向后,我的PHP脚本中没有其他工作。

我正在使用CURL假装从浏览器运行,我收到302错误以重定向到页面。我只需要在重定向后自动保存HTML页面内容。

欢迎任何建议。

$new_url =  'www.example.com';
$path = 'C:/page.html';

// redirect to new pages
header('Location:'. $new_url);
exit();

// load and save the file
$doc = new DOMDocument();
$doc->loadHTMLFile($new_url);
$doc->saveHTMLFile($path);

1 个答案:

答案 0 :(得分:2)

然后尝试在HTML之前保存redirect

$new_url =  'www.example.com';
$path = 'C:/page.html';

// load and save the file
$doc = new DOMDocument();
$doc->loadHTMLFile($new_url);
$doc->saveHTMLFile($path);

// redirect to new pages
header('Location:'. $new_url);
exit();
相关问题