php cURLでログイン後のページを取得
2013/04/26
ログインして、ログイン後のページを取得
<?php
$params = array(
"login-name" => "name",
"login-pass" => "pass"
"submit" => "ログイン",
);
$ch = curl_init("http://www.phppro.jp/members/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$output = curl_exec($ch);
curl_close($ch);
print $output;
?>
$params = array(
"login-name" => "name",
"login-pass" => "pass"
"submit" => "ログイン",
);
$ch = curl_init("http://www.phppro.jp/members/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$output = curl_exec($ch);
curl_close($ch);
print $output;
?>
ログイン後、別のページを取得
<?php
$params = array(
"login-name" => "nakamuraya",
"login-password" => "gerogero",
"submit" => "ログイン"
);
$fp = fopen("tmp", "w");
$ch = curl_init("http://www.phppro.jp/members/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_WRITEHEADER, $fp);
output = curl_exec($ch);
$fclose($fp);
curl_close($ch);
print "CURL OUTPUT:\n{$output}\n";
$ch = curl_init("http://www.phppro.jp/members/history.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "tmp");
curl_setopt($ch, CURLOPT_POST, TRUE);
$output = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
print "CURL OUTPUT:\n{$output}\n";
?>
$params = array(
"login-name" => "nakamuraya",
"login-password" => "gerogero",
"submit" => "ログイン"
);
$fp = fopen("tmp", "w");
$ch = curl_init("http://www.phppro.jp/members/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_WRITEHEADER, $fp);
output = curl_exec($ch);
$fclose($fp);
curl_close($ch);
print "CURL OUTPUT:\n{$output}\n";
$ch = curl_init("http://www.phppro.jp/members/history.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "tmp");
curl_setopt($ch, CURLOPT_POST, TRUE);
$output = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
print "CURL OUTPUT:\n{$output}\n";
?>