我需要登录一个网站,然后它会将我重定向到另一个我必须发布数据的页面;我已经编写的代码将使我成功登录,并将我重定向到我必须发布(发送 $_POST)数据的页面,但我不知道如何发布它(使用某些会话/cookies 开始另一个请求已经开始)这是代码。
$url = "http://site.com/account.php?s_id=&d=y";
$email = "EMAIL@EMAIL.COM";
$password = "PASS";
$postfields = "email=$email&password=$password&submit=1&do=login&forward=&communicate=&communicate_id=1";
$postfield = "message=doit";
$cookiefile = tempnam("/tmp", "cookies");
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
$ch2 = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_HEADER, 0); // Get the header
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_exec($ch);
curl_close($ch);