Forums

Using Curl to post an array

gnikol1 03 Aug, 2010
Hi,

I am looking for a solution in the following problem.
The curl plugin is posting the variable seperated, I would like to post the variable as an array, simulating the below:

<?php

$url = "http://www.yourdomain.com/whmcs/includes/api.php"; # URL to WHMCS API file
$username = "Admin"; # Admin username goes here
$password = "demo"; # Admin password goes here

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "addinvoicepayment"; #action performed by the API:Functions
$postfields["invoiceid"] = "1";
$postfields["transid"] = "TEST";
$postfields["gateway"] = "mailin";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

?>


Is it possible?

Thanks a lot for the support.
George
GreyHead 03 Aug, 2010
Hi George,

That's exactly what the CURL plugin does - have you tested?

Bob
gnikol1 31 Jul, 2012
Hi
I tested but the case is the IP that is posting the cURL data is the IP of the PC using the form.
My problem is that the IP needs to be IP of the server.
Is this possible to be performed?

Thanks
GreyHead 01 Aug, 2012
Hi George,

I'm not sure I understand the problem? There is no IP address in the code you posted. If you need to add one to the Param/Fields box then you can add any value that you like - assuming that you can access the server IP address.

Bob
This topic is locked and no more replies can be posted.