<p>To get the balance of something you need an account, which is best created dynamically with PHP. You would use the <code>getnewaddress("echo uniqid()");</code> in PHP as an example of generating a new account for every user.</p>

CC BY-SA 4.0
2019-05-23T08:40:00.467Z
2019-05-23T08:40:00.467Z
frogman578
<p>I'm trying to get the balance of a specific address in my PHP session, I currently have this:</p>

<pre><code>&lt;?php
  require 'header.php';
  include 'Includes/Bitcoin/easybitcoin.php';
  $bitcoin = new Bitcoin('user', 'password', 'localhost', '8332');
  $wallet = $_SESSION['UserWallet'];
  $balance = $bitcoin-&gt;getbalance($wallet);
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;meta charset="utf-8"&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body style="font-family: sans-serif;"&gt;
  &lt;b&gt;Wallet address: &lt;?php print_r($wallet); ?&gt;&lt;/b&gt;
  &lt;br /&gt;
  &lt;b&gt;Account balance: ฿&lt;?php print_r($balance); ?&gt;&lt;/b&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Where the <code>$_SESSION['UserWallet']</code> contains the bitcoin address, when I run this it returns an error, how does it work?</p>

CC BY-SA 4.0
2019-04-07T23:02:53.953Z
That is not how the getbalance RPC works.
Pieter Wuille
CC BY-SA 4.0
2019-04-08T01:09:22.620Z
Perhaps read the documentation before trying to make a product that handles other people's money.
Claris
CC BY-SA 4.0
2019-04-08T07:28:23.753Z
@PieterWuille What parameters are used? Can they be variables in any way?
frogman578
<json-rpc><php>
Run specific RPC commands in PHP?
frogman578
# Run specific RPC commands in PHP?

(Asked by: username_0 on 2019-04-07)

I'm trying to get the balance of a specific address in my PHP session, I currently have this:

```
<?php
  require 'header.php';
  include 'Includes/Bitcoin/easybitcoin.php';
  $bitcoin = new Bitcoin('user', 'password', 'localhost', '8332');
  $wallet = $_SESSION['UserWallet'];
  $balance = $bitcoin->getbalance($wallet);
?>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
</head>
<body style="font-family: sans-serif;">
  <b>Wallet address: <?php print_r($wallet); ?></b>
  <br />
  <b>Account balance: ฿<?php print_r($balance); ?></b>
</body>
</html>

```

Where the `$_SESSION['UserWallet']` contains the bitcoin address, when I run this it returns an error, how does it work?

**Tags:** json-rpc, php

> **Comments:**
> **username_1**: That is not how the getbalance RPC works.  
> **username_2**: Perhaps read the documentation before trying to make a product that handles other people's money.  
> **username_0**: @username_1 What parameters are used? Can they be variables in any way?  

---

## 1 answers

### Answer by username_0 on 2019-05-23. Score: 0 | Accepted answer

To get the balance of something you need an account, which is best created dynamically with PHP. You would use the `getnewaddress("echo uniqid()");` in PHP as an example of generating a new account for every user.


---

