<p>Not sure if you're still looking for an answer, but I just stumbled upon this myself and for the benefit of anyone running into this.</p>

<p>Even though it's called cookie based authentication, you still authenticate via Basic HTTP.</p>

<p>Let's say your cookie was <code>__cookie__:somerandomlongstring</code> then:</p>

<ul>
<li>Username <code>__cookie__</code></li>
<li>Password <code>somerandomlongstring</code></li>
</ul>

<p>I figured this out after finding <a href="https://github.com/bitcoin/bitcoin/issues/10218#issuecomment-294344689" rel="noreferrer">this comment on Github</a></p>

CC BY-SA 3.0
2017-06-28T21:15:56.563Z
2017-06-28T21:15:56.563Z
tsak
<p>Since 0.12 RPC uses a "random cookie":<a href="https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.12.0.md#rpc-random-cookie-rpc-authentication" rel="nofollow">https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.12.0.md#rpc-random-cookie-rpc-authentication</a> for authentication, but it's not clear how to use this cookie when accessing RPC.</p>

<p>I'm trying things like the below, without success (401 Unauthorized)</p>

<pre><code>$Request = array(
    'http' =&gt; array(
        'method' =&gt; 'POST',
        'header' =&gt; "Content-type: application/json\r\n".
                    'Cookie: __cookie__=contentsOf.cookie',
        'content' =&gt; $Params
        )
    );
if (!$Response = file_get_contents(BITCOIN_RPC_URL, false, stream_context_create($Request))) {
    return false;
}
</code></pre>

<p>Every example I find online uses the user:pass authentication, I've yet to see an example using cookies.</p>

<json-rpc><php>
Using PHP with RPC and cookie
Whetock
# Using PHP with RPC and cookie

(Asked by: username_0 on 2016-04-17)

Since 0.12 RPC uses a "random cookie":https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.12.0.md#rpc-random-cookie-rpc-authentication for authentication, but it's not clear how to use this cookie when accessing RPC.
I'm trying things like the below, without success (401 Unauthorized)
$Request = array(
    'http' => array(
        'method' => 'POST',
        'header' => "Content-type: application/json\r\n".
                    'Cookie: __cookie__=contentsOf.cookie',
        'content' => $Params
        )
    );
if (!$Response = file_get_contents(BITCOIN_RPC_URL, false, stream_context_create($Request))) {
    return false;
}

Every example I find online uses the user:pass authentication, I've yet to see an example using cookies.

**Tags:** json-rpc, php


---

## 1 answers

### Answer by username_1 on 2017-06-28. Score: 6

Not sure if you're still looking for an answer, but I just stumbled upon this myself and for the benefit of anyone running into this.

Even though it's called cookie based authentication, you still authenticate via Basic HTTP.

Let's say your cookie was `__cookie__:somerandomlongstring` then:

* Username `__cookie__`
* Password `somerandomlongstring`

I figured this out after finding [this comment on Github](https://github.com/bitcoin/bitcoin/issues/10218#issuecomment-294344689)


---

