Reputation: 1631
I am trying to curl post with php
The page I am trying to submit has codes like this
<input name="fname" type="hidden" value="show">
<input name="method" type="submit" value="Continue">
I am trying to simulate this "sumbit"(continue) button and follow redirection with php
$post= array("method=>Continue")
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
$h = curl_exec($ch);
echo $h;
What should I have in the $post= array(?). I have tried $post= array(name => method). Not working..any ideas?
Upvotes: 1
Views: 350
Reputation: 29498
You can set the CURLOPT_POSTFIELDS
option to the array itself:
$post = array(
"method" => "Continue",
"fname" => "show"
);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
Upvotes: 1