0
我需要登錄到一個網站,然後它將我重定向到其他頁面,我必須發佈數據; 我已經編寫的代碼將會成功登錄到我,並將我重定向到我必須發佈(發送$ _POST)數據的頁面,但我不知道如何發佈它(使用某個會話/已經開始的cookies)這是代碼。使用curl登錄和發佈數據php
$url = "http://site.com/account.php?s_id=&d=y";
$email = "[email protected]";
$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);
你是什麼意思發佈數據?請澄清 – 2013-02-20 01:15:57
將其發送爲$ _POST – Hamza 2013-02-20 01:17:00
儘量不要關注位置並解析重定向答案並在隨後的調用中發帖。 – user993553 2013-02-20 01:21:06