如果网站使用基本身份验证,如何使用PHP获取网站源代码?通过身份验证URL通过PHP获取HTML源代码
<?php
$ch = curl_init("http://domain.com/password.html");
$fp = fopen("source.txt", "w");
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_FILE, $fp);
$output = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
我在做什么错?
您是否收到任何错误?预期的结果是什么?你究竟得到了什么? – 2013-05-05 04:14:11
我得到空文件(source.txt)...并没有错误... – mirsad 2013-05-05 04:19:18
你似乎没有写信给source.txt。也许你错过了'fwrite($ fp,$ output);'? – 2013-05-05 04:20:11