Reputation: 352
I'm trying a basic thing. I have two files: curl.php and form.php
curl.php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/test/test34_curl_post/form.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'nabc' => 'fafafa'
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
form.php
<form action="form.php" method="post">
<input type="hidden" name="nabc" value="abc" />
<input type="submit" name="submit" value="Send" />
</form>
<?php
if(isset($_POST['submit']))
{
echo '<br />Form sent!'.$_POST['nabc'];
}
?>
what I'm hoping to get is as the result of running curl.php, to see "Form sent!". It seems as if it wasn't sent as POST. In firebug (network) there is only one GET request and what I get is the form, nothing sent. Anyone, please help.
Upvotes: 1
Views: 5757
Reputation: 11190
You're not sending 'submit'
in your POST data so isset($_POST['submit'])
will be false. You need to do the following:
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'nabc' => 'fafafa',
'submit' => 'Send' // if you want 'submit' in $_POST you need this
));
Upvotes: 1