Page 1 of 1

Form action cURL help

Posted: Wed Apr 22, 2009 8:51 am
by WLamont
Heya all, I'm very new to php so you'll have to excuse me if there is something really obvious all my research has missed. I'm trying to get this working within a XHTML Strict coded page.

I'm trying to implement a sms-gateway on my website provided by a third party. i have a password and Username provided by the third party to post to their server. What I've been trying to achieve is a way to have the form on my site send the clients data to the php script (containing my additional login details) which are forwarded to the third party server for processing and the repsonse is sent back to the original page. I don't want the user loading the either the internal php script or the external site's page. This is obviously (well at least I hope so) a job for cURL.

Can anyone point me to an example if it exists to have the html form action cURL the form output array to the internal php file which will inturn take the forms output, include the extra information into a new array and cURL that to the external site and then feed the result back to the original page?

Things I've got from my searches so far:
The html page needs the initial php code which is triggered by if(isset(variable[])) {....
The code needs to take the two array elements from the form (sender and message) and cURL that through to the sms.php
- I'm not exactly sure how to handle the obtaining of the data into the array then into the next php document to be added to a new array.

code provided by the SMS party which works as planned. So far this works when it is called normally by the form but then sends the used to a blank page to await the response message.

<?php

$post_data = array();
$post_data['username'] = "username";
$post_data['password'] = "password";
$post_data['mobilenumber'] = "040000000";
$post_data['message'] = $_POST["message"];
$post_data['sender'] = $_POST["sender"];
$post_data['messagetype'] = "Text";
$post_data['referencenumber'] = "xxxxxx";
$url = "https://externalurl.com";

$o="";
foreach ($post_data as $k=>$v)
{
$o.= "$k=".utf8_encode($v)."&";
}
$post_data=substr($o,0,-1);

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = curl_exec($ch);

echo "Result: $result\n";

?>

As you can see in its present form on message and sender need to be obtained from the html form.

Anyway any assistance or direction to look for assistance would be greatly appreciated. Note that my php skills are very average so any responses are going to require some explanation for me to get my head around