not exactly a complete account system (maybe half of it),
but i'd like to share my SAMPLE_JSON.PHP anyway, maybe it's of use for someone.
it's using cURL to connect to the API.
<?php
// IMPORTANT!
// This is NOT SECURE by default, restrict access to this script,
// password protect it, check the referrer, session, or whatever else you like.
// Anyone able to reach this script AS IS is able to send your balance to another address!
// simply call commands like this
// ./SAMPLE_JSON.PHP?command=getinfo
// or with parameter
// ./SAMPLE_JSON.PHP?command=getnewaddress¶meter=username
// ./SAMPLE_JSON.PHP?command=getreceivedbylabel¶meter=username
// set the URL to JSON-API
$url = 'http://127.0.0.1:8332';
// set a JSON id
$jsonid = 'unique';
// which command has been called?
if ($_GET['command'])
$command = $_GET['command'];
// and if what parameter?
if ($_GET['parameter'])
$para = $_GET['parameter'];
if ($para) $parb = array($para);
// if none, we create an empty array
else $parb = array();
// and encode all of it to JSON
$arr = array (
'id'=>$jsonid,
'method'=>$command,
'params'=>$parb
);
$data = json_encode($arr);
// run cURL to transfer our data
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
// debug - to check the response we can just view our JSON output here
echo $output."<br>\n\r";
// if $output looks ok, we decode it here and close our cURL session
$obj = json_decode($output);
curl_close($ch);
// and that's it, just handle the $obj and show it, add/compare it to DBs, or whatever else is needed.
// below is just some basic samples
if ($obj->error != "null")
echo $obj->error;
if ($obj->id == $jsonid) {
if (is_object($obj->result))
$info = get_object_vars($obj->result);
if ($command == "getinfo") {
if ($info) {
echo "Balance: ". $info['balance']."<br>\n\r";
echo "Blocks: ". $info['blocks']."<br>\n\r";
echo "Connections: ". $info['connections']."<br>\n\r";
if ($info['generate'])
$gen = "yes";
else
$gen = "no";
echo "Generating: ". $gen."<br>\n\r";
echo "Difficulty: ". $info['difficulty']."<br>\n\r";
}
}
if ($command == "getreceivedbylabel") {
echo $obj->result."\n";
}
if ($command == "getnewaddress") {
echo $obj->result."\n";
}
}
?>
be sure to restrict access somehow!
I guess there's easier, or simpler ways to do this, maybe you know of one.