form method POST input type text name code button type submit Ok butto

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<form method="POST">
<input type="text" name="code">
<button type="submit">Ok</button>
</form>
<?php
function api_query($api_name, array $req = array())
{
$mt = explode(' ', microtime());
$NONCE = $mt[1] . substr($mt[0], 2, 6);
$key = ""; //TODO replace with your api key from profile page
$secret = ""; //TODO replace with your api secret from profile page
$url = "http://api.exmo.com/v1/$api_name";
$req['nonce'] = $NONCE;
// generate the POST data string
$post_data = http_build_query($req, '', '&');
$sign = hash_hmac('sha512', $post_data, $secret);
// generate the extra headers
$headers = array(
'Sign: ' . $sign,
'Key: ' . $key,
);
// our curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; PHP client; ' . php_uname('s') . '; PHP/' . phpversion() . ')');
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: ' . curl_error($ch));
$dec = json_decode($res, true);
if ($dec === null)
throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
return $dec;
}
if(isset($_POST['code'])) {
var_dump(api_query("excode_load", Array("code" => $_POST['code'])));
}
?>