cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: how to handle a callback function in curl to php

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 11 Nov 2013 22:53:23 +0100

On Sun, Nov 10, 2013 at 08:06:13PM -0500, Robert Lefebure wrote:
> I've never had to handle something being sent by an outside server before and I
> don't know where to begin.
>
> They give me this as an example:
>
> curl example (url callback):     curl -H "Authorization: <apikey>" http://
> www.bitcoinmonitor.net/api/v1/agent/17/notification/url/ -X POST
> -d"req_confirmations=3&url=http://my.shop.com/payment/"
>
> I've set the url config of my php page at their site so I expect I change "url=
> http://my.shop.com/payment/"" to what I told them. Then,  I've got the API key
> from them too and change that.
>
> I don't understand their "curl -H "authentication ... etc

That looks to me like an example curl command-line that would simulate their
servers sending a request to your site, and is something that gets discussed on
this list.

> because all the curl I know starts with
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, $file);
> curl_setopt($ch, CURLOPT_POST, 1);
> etc

That's an example of the PHP/CURL binding, which is not a topic of this list.

> This is an example of the data I would be getting from them in the POST body
> ...
>
> {
> "signed_data": {
> "amount": 122678000,
> "userdata": "",
> "confirmations": 2,
> "amount_btc": "1.22678000",
> "address": "12r9JzPNnyWs2j1s9KLW5keqBr4kbJjxz6",
> "created": "2012-02-19 10:37:20.203541",
> "txhash": "e0c84120068bfefddab051e751f3df963c4ed29e7b13eadac026e6f17f55fb06",
> "agent": "callback_test"
> },
> "signature": "38a25ec14b9ffcfe98938f3e35ac9cf41de2a971"
> }
>
>
> So basically my question is how can I get the post data (in PHP) from wjhat
> they say in their example (
>  curl -H "Authorization: <apikey>" http://www.bitcoinmonitor.net/api/v1/agent/
> 17/notification/url/ -X POST -d"req_confirmations=3&url=http://my.shop.com/
> payment/" )?
>
> Is it the CURLOPT_HEADERFUNCTION or the  CURLOPT_READFUNCTION?

That's a question for a PHP mailing list; this mailing list covers the curl
command-line tool. But, as a hint, if I understand your request correctly, you
don't need PHP/CURL for this operation. You probably want a basic PHP form
handler that decodes JSON, e.g. json_decode(file_get_contents('php://input'));

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-11-11