パスワードで保護されたページにログインして保護されたページを取得する次の php コードがあります。
ログイン機能を再度使用する代わりに、Cookie ファイルを使用して次の保護されたページを開きたい ! つまり、他の保護されたページを取得するためのログイン手順をバイパスしたいだけです。
これを行う方法を教えてもらえますか?
注: 私のログイン関数は、スクリプトと同じフォルダーに表示されない Cookie を作成しません!誰か教えてください。
<?
$ch=login();
$html=downloadUrl('http://www.example.com/page1.asp', $ch);
////echo $html;
function downloadUrl($Url, $ch){
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
return $output;
}
function login()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/login.asp'); //login URL
curl_setopt ($ch, CURLOPT_POST, 1);
$post_array = array(
'txtUserName'=>'brad',
'txtPassword'=>'bradpassword',
);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_array);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
return $ch;
}
?>
<html>
<br>
<textarea rows="30" cols="150"><?PHP print_r($html); ?></textarea>
</html>