Hi am trying to post some data on a website using CURL. The posting process has 3 steps.
1. enter a URL, submit and get to the 2nd step with some fields already completed
2. submit again, after you entered some more data and preview the form.
3. submit the final data.
The problem is that after the second step, the form data looks like this
POSTDATA =-----------------------------12249266671528
Content-Disposition: form-data; name="title"
Filme 2010, filme 2009, filme noi, programe TV, program cinema, premiere cinema, trailere filme - CineMagia.ro
-----------------------------12249266671528
Content-Disposition: form-data; name="category"
3
-----------------------------12249266671528
Content-Disposition: form-data; name="tags"
filme, programe tv, program cinema
-----------------------------12249266671528
Content-Disposition: form-data; name="bodytext"
Filme 2010, filme 2009, filme noi, programe TV, program cinema, premiere cinema, trailere filme
-----------------------------12249266671528
Content-Disposition: form-data; name="trackback"
-----------------------------12249266671528
Content-Disposition: form-data; name="url"
http://cinemagia.ro
-----------------------------12249266671528
Content-Disposition: form-data; name="phase"
2
-----------------------------12249266671528
Content-Disposition: form-data; name="randkey"
9510520
-----------------------------12249266671528
Content-Disposition: form-data; name="id"
17753
-----------------------------12249266671528--
I am stuck trying to devise an algorithm that will generate this kind of POST data for the second step. Just to mention the URL of the form never changes. It is always: http://www.xxx.com/submit. There is only a hidden input called "phase" that changes according to the step i am currently on (phase = 1, phase = 2, phase = 3). Any help, be it either code, pseudo-code or just guidance would be greatly appreciated.
My code so far:
function postBlvsocialbookmarkingcom($curl,$vars) {
extract($vars);
$baseUrl = "http://www.blv-socialbookmarking.com/";
//step 1: login
$curl->setRedirect();
$page = $curl->post ($baseUrl.'login.php?return=/index.php', array ('username' => $username, 'password' => $password, 'processlogin' => '1', 'return' => '/index.php'));
if ($err = $curl->getError ()) {
return $err;
}
//post step 1----
//get random key
$page = $curl->post($baseUrl.'/submit', array());
$randomKey = explode('<input type="hidden" name="randkey" value="',$page);
$randKey = explode('"',$randomKey[1]);
//-------------------------------------
$page = $curl->post($baseUrl.'/submit', array('url'=>$address,'phase'=>'1','randkey'=>$randKey[0],'id'=>'c_1'));
if ($err = $curl->getError ()) {
return $err;
}
//echo $page;
//
//post step 2
$page = $curl->post ($baseUrl.'/submit', array ('title' => $title, 'category'=>'1', 'tags' => $tags, 'bodytext' => $description, 'phase' => '2'));
if ($err = $curl->getError ()) {
return $err;
}
echo $page;
//post step 3
$page = $curl->post ($baseUrl.'/submit', array ('phase' => '3'));
if ($err = $curl->getError ()) {
return $err;
}
echo $page;
}