Author

Topic: Need coinhive code examples (php) (Read 384 times)

newbie
Activity: 4
Merit: 0
November 05, 2017, 10:58:01 PM
#6
Alright i finally got it by fiddling with some php answers over the net. For future reference, here's how to show a name and balance of a user:

Code:
$url "https://api.coinhive.com/user/balance?secret=SecretAPIkey&name=UserToLookup";
$json file_get_contents($url);
$json_data json_decode($jsontrue);
echo 
"My name: "$json_data["name"];
echo 
"
My balance: "
$json_data["balance"];
?>


Cheers! Smiley
newbie
Activity: 4
Merit: 0
November 05, 2017, 10:29:48 PM
#5
Alright, now it gives a blank page. However if I check the source it printed a few
's so this might mean progress
full member
Activity: 169
Merit: 100
SORRY
November 05, 2017, 10:17:35 PM
#4
Hi, thanks for your reply. Here's my starting code, just to be able to handle a json string from php:

Code:
$url=sprintf('php://api.coinhive.com/user/balance?secret=MySecretKey&name=SomeName');
$data=file_get_contents($url);
$json=json_decode($data);
foreach (
$json as $character) {
echo $character->name '
'
;
}
 
?>


This shoots out a http error 500 on my box.
Any help appreciated.


try change php://api.coinhive.com to https://api.coinhive.com
newbie
Activity: 4
Merit: 0
November 05, 2017, 07:07:02 PM
#3
Hi, thanks for your reply. Here's my starting code, just to be able to handle a json string from php:

Code:
$url=sprintf('php://api.coinhive.com/user/balance?secret=MySecretKey&name=SomeName');
$data=file_get_contents($url);
$json=json_decode($data);
foreach (
$json as $character) {
echo $character->name '
'
;
}
 
?>


This shoots out a http error 500 on my box.
Any help appreciated.
hero member
Activity: 1218
Merit: 534
November 05, 2017, 08:50:09 AM
#2
Share your code and I'll take a look at it.
newbie
Activity: 4
Merit: 0
November 05, 2017, 08:26:40 AM
#1
Hi everyone,
I just discovered coinhive and wanted to fiddle with it with a personal lamp server in a virtual machine for testing purposes. Coinhive's documentation is pretty limited and real life makes it that I often have to interrupt my coding & testing sessions. However I've been lurking and reading in the cryptocurrency for about 2 years and I would like to have a small and unique faucet project.

Up to now, my web skills are pretty limited to installing WordPress scripts and moving mysql data around with php. I want to get to the next level of web integration, and with good examples I can learn quickly. Basically I'm trying to tell my php machine to fetch the json data and display it to the screen. Then, later on I would like to store the json data in a mysql database so I could show some stats. But up to now, all I get is either blank pages or http 500 errors. Even just making a simple console to graph the data is overwhelming. btw, do I need to have a https certificate to fetch https urls? That shows how much behind I feel like Tongue

While searching, I landed on beniamino38's hivefaucet wich was exactly the general idea I had in mind, except with a few variances like rewarding with more coins than btc or monero. I also thought of some forum "like" or "up" button that would hash a little before accepting, therefore showing a true value of encouragement to the poster (since the liker spent some cpu cycles for him/her), then sharing something like 1/3 to the poster, the liker and the hoster.

But again, usable examples are lacking, so useable examples would help me a lot. I'll make sure to share my creation asap Smiley
Jump to: