Author

Topic: Need help about PHP and API (Read 556 times)

legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 29, 2017, 09:19:17 AM
#18
Quote
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

FWITW, doing this or just error_reporting(0) is the same. It takes a binary flag as arguments. It's like doing 0xFFFF & ~0xFFFF which obviously equals...0.

Do not forget than you are talking with an "old noob"

You so far helped me...about the error you have seen...with the secret key:
It was I believe during my test...

So far I so in progress:
http://u2cloudmining.winspiral.net/codshare.php

I had 100 other questions,but in general I try to search and understand by myself first.
And my search are often so "simple" that it is not explained in the "help"...
I'm even till lost about the ' ' and " " I have sometimes to put in the programmes...
Now with "java script" it is not to make me easier...
Fortunately I have time (lol)

And "English" is not my native language...


newbie
Activity: 29
Merit: 0
September 29, 2017, 04:53:54 AM
#17
Quote
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

FWITW, doing this or just error_reporting(0) is the same. It takes a binary flag as arguments. It's like doing 0xFFFF & ~0xFFFF which obviously equals...0.
full member
Activity: 356
Merit: 113
September 28, 2017, 11:03:14 PM
#16
Quote
I do not understand your "add a @ in front of the call"

In PHP, adding a @ in front of a call disables any error related to this call. But you should globally disable error reporting in your php.ini.
Just read the doc Wink


I have put this:
Quote
ini_set('display_errors', 'off');
error_reporting(0);
But I do not see a difference.

about the @ I have not yet foud.

I don't think it's 'off', for PHP I'm pretty sure you want:

ini_set('display_errors', 0);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
newbie
Activity: 29
Merit: 0
September 28, 2017, 03:08:06 PM
#15
Quote
I do not understand your "add a @ in front of the call"

In PHP, adding a @ in front of a call disables any error related to this call. But you should globally disable error reporting in your php.ini.
Just read the doc Wink


I have put this:
Quote
ini_set('display_errors', 'off');
error_reporting(0);
But I do not see a difference.

about the @ I have not yet foud.

@ just tells PHP not to trigger an error for a particular call. (e.g. when you don't globally disable all the errors)
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 03:03:16 PM
#14
Quote
I do not understand your "add a @ in front of the call"

In PHP, adding a @ in front of a call disables any error related to this call. But you should globally disable error reporting in your php.ini.
Just read the doc Wink


I have put this:
Quote
ini_set('display_errors', 'off');
error_reporting(0);
But I do not see a difference.

about the @ I have not yet foud.
newbie
Activity: 29
Merit: 0
September 27, 2017, 01:59:04 PM
#13
Quote
I do not understand your "add a @ in front of the call"

In PHP, adding a @ in front of a call disables any error related to this call. But you should globally disable error reporting in your php.ini.
Just read the doc Wink
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 12:05:48 PM
#12
Well, you just leaked your secret key from coin-hive because file_get_contents failed and disclosed the URL you're trying to call (with the secret key embedded).

1. Disable PHP errors on production!
2. We now know we shouldn't trust the thing you're calling 'U2cloudmining'



Thanks and how can I do this?
and test it?

http://php.net/manual/en/function.error-reporting.php

If it's just for file_get_contents, add a @ in front of the call.

I have put

error_reporting(0);

I do not understand your "add a @ in front of the call"
newbie
Activity: 29
Merit: 0
September 27, 2017, 11:40:06 AM
#11
Well, you just leaked your secret key from coin-hive because file_get_contents failed and disclosed the URL you're trying to call (with the secret key embedded).

1. Disable PHP errors on production!
2. We now know we shouldn't trust the thing you're calling 'U2cloudmining'

https://i.imgur.com/pKwxIK7.jpg

Thanks and how can I do this?
and test it?

http://php.net/manual/en/function.error-reporting.php

If it's just for file_get_contents, add a @ in front of the call.
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 10:54:23 AM
#10
Well, you just leaked your secret key from coin-hive because file_get_contents failed and disclosed the URL you're trying to call (with the secret key embedded).

1. Disable PHP errors on production!
2. We now know we shouldn't trust the thing you're calling 'U2cloudmining'



Thanks and how can I do this?
and test it?
newbie
Activity: 29
Merit: 0
September 27, 2017, 10:17:05 AM
#9
Quote

Well, you just leaked your secret key from coin-hive because file_get_contents failed and disclosed the URL you're trying to call (with the secret key embedded).

1. Disable PHP errors on production!
2. We now know we shouldn't trust the thing you're calling 'U2cloudmining'

https://i.imgur.com/pKwxIK7.jpg
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 09:43:04 AM
#8
Quote
Both codes work
but I am not able to replace :
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
by
 
$data='$file';
why?

Because :

1. If $file contains the JSON, it must be either just $file (no quote, or double quote instead of single) or just use $file as the data.
2. If you want to read the data from a file, use something like $data = file_get_contents($path_to_file) (or whatever is the API you get your JSON from)

Anyway, this is very basic programming. If you're planning to deal with other people money, you shouldn't do this yourself.

Thanks paraboul
it seems it works now.
Do not worry,I do it just for the fun.

Thanks to you all...

you can see my test here:
http://www.winspiral.net/u2cloudmining/minertest.php

Both codes work...thanks again.

newbie
Activity: 29
Merit: 0
September 27, 2017, 09:31:19 AM
#7
Quote
Both codes work
but I am not able to replace :
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
by
 
$data='$file';
why?

Because :

1. If $file contains the JSON, it must be either just $file (no quote, or double quote instead of single) or just use $file as the data.
2. If you want to read the data from a file, use something like $data = file_get_contents($path_to_file) (or whatever is the API you get your JSON from)

Anyway, this is very basic programming. If you're planning to deal with other people money, you shouldn't do this yourself.
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 09:27:12 AM
#6
This is quite dumb, but if you really want to have the named variable exported to the global namespace, you can use extract()

e.g.

Code:
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
extract((array)json_decode($data), EXTR_SKIP);

echo "Hey $name, your balance is $balance";

Anyway, you shouldn't do this and avoid trashing the global namespace (or current scope), just use a regular object, like :

Code:
$obj = json_decode($data);
echo "Hey $obj->name, your balance is $obj->balance";

Both codes work
but I am not able to replace :
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
by
 
$data='$file';
why?
newbie
Activity: 29
Merit: 0
September 27, 2017, 08:39:25 AM
#5
This is quite dumb, but if you really want to have the named variable exported to the global namespace, you can use extract()

e.g.

Code:
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
extract((array)json_decode($data), EXTR_SKIP);

echo "Hey $name, your balance is $balance";

Anyway, you shouldn't do this and avoid trashing the global namespace (or current scope), just use a regular object, like :

Code:
$obj = json_decode($data);
echo "Hey $obj->name, your balance is $obj->balance";
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 08:14:31 AM
#4
What are you trying to achieve? I can't help you much if i don't know what you want to do. If you just want to assign data from the json response to the variables, then "Saovy" has pointed you in the right direction, but i doubt that is the only thing you want to do with these variables. Are you building a database of some sort? If you can explain more on what you are trying to achieve, i can only then help you out with a script.

I will try to say more:

After doing what Saovy said about I have this

Quote
object(stdClass)#1 (5) { ["success"]=> bool(true) ["name"]=> string(9) "minerpage" ["total"]=> int(932352) ["withdrawn"]=> int(0) ["balance"]=> int(932352) } array(5) { ["success"]=> bool(true) ["name"]=> string(9) "minerpage" ["total"]=> int(932352) ["withdrawn"]=> int(0) ["balance"]=> int(932352) }

But I try to have in my script

echo " balance of $name is $balance";

to see on my site
Balance of minerpage is 932352
legendary
Activity: 1512
Merit: 1218
Change is in your hands
September 27, 2017, 07:36:57 AM
#3
What are you trying to achieve? I can't help you much if i don't know what you want to do. If you just want to assign data from the json response to the variables, then "Saovy" has pointed you in the right direction, but i doubt that is the only thing you want to do with these variables. Are you building a database of some sort? If you can explain more on what you are trying to achieve, i can only then help you out with a script.
newbie
Activity: 50
Merit: 0
September 27, 2017, 05:01:29 AM
#2
Use json_decode

http://php.net/manual/en/function.json-decode.php

it will turn the json your api returns into an object you can use in any way you see fit.
legendary
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
September 27, 2017, 03:56:58 AM
#1
Hello,
I have found many things on google but I could not use it because my programmer level is low.
Perhaps could you help me or guide me.

Form an API I get this:

Quote
{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}

How can I have by script

$name="winspiral"
$total=196864
$withdraw=0
$balance=196864

Thanks for your help.
Jump to: