1

I'm new to php development and i just heard of curl. i have this data i post in a form action

<form id="new_member_sms" name="new_member_sms" method="post" action="http://myserver.com/app_api.php?view=send_sms&amp;&amp;user=username&amp;&amp;pass=password&amp;&amp;message=hello+this+message+is+dynamic+from+server&amp;&amp;sender_id=BlaySoft&amp;&amp;to=<?php echo $row_rs_sms['phone_no']; ?>&amp;&amp;key=4">

</form>

I want to know if there's a way i can wrap this post message "http://myserver.com/app_api.php?view=send_sms&amp;&amp;user=username&amp;&amp;pass=password&amp;&amp;message=hello+this+message+is+dynamic+from+server&amp;&amp;sender_id=BlaySoft&amp;&amp;to=<?php echo $row_rs_sms['phone_no']; ?>&amp;&amp;key=4" in a php curl and send it to the server

i_user
  • 511
  • 1
  • 4
  • 21
  • Possible duplicate of [Using cURL to POST data to a form](http://stackoverflow.com/questions/9446085/using-curl-to-post-data-to-a-form) – Matheno Dec 18 '15 at 15:15

2 Answers2

2

Basic version of curl post with PHP in your case would be the following:

$data = array(
    'view' => 'send_sms',
    'user' => 'username',

    // ...
    // add remaining post fields here
    // ...
);

$url = 'http://myserver.com/app_api.php';

$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_exec($handle);

The $data array should contain all parameters which you want to send via POST

pavlovich
  • 1,935
  • 15
  • 20
0

If you want to submit form (WITHOUT using curl) include all of your parameters as hidden inputs inside the form:

<form id="new_member_sms" name="new_member_sms" method="post" action="http://myserver.com/app_api.php">

  <input type="hidden" name="view" value="send_sms">
  <input type="hidden" name="user" value="username">

  <!-- and so on - put all your parameters here -->

  <input type="submit" value="Submit">
</form>
pavlovich
  • 1,935
  • 15
  • 20
  • ohk, i get you now. i want to submit without the form, so i will use the curl. meaning every parameter that i want it to be sent should be included in the curl. for example 'message' => 'hello', to="021212565". is that it – i_user Dec 18 '15 at 15:51
  • @i_user yes, exactly like this – pavlovich Dec 18 '15 at 15:52
  • please in the url should in include the "?" or leave it as it is:http://myserver.com/app_api.php or http://myserver.com/app_api.php? – i_user Dec 18 '15 at 15:53
  • @i_user it should be exactly like in my other answer, that is without `"?"` – pavlovich Dec 18 '15 at 15:54