winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 07:56:58 AM |
|
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: {"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.
|
|
|
|
|
Thekool1s
Legendary
Offline
Activity: 1512
Merit: 1218
Change is in your hands
|
|
September 27, 2017, 11:36:57 AM |
|
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.
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 12:14:31 PM |
|
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 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
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 27, 2017, 12:39:25 PM Last edit: September 27, 2017, 12:49:54 PM by paraboul |
|
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. $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 : $obj = json_decode($data); echo "Hey $obj->name, your balance is $obj->balance";
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 01:27:12 PM |
|
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. $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 : $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?
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 27, 2017, 01:31:19 PM |
|
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.
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 01:43:04 PM Last edit: September 27, 2017, 01:56:16 PM by winspiral |
|
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.phpBoth codes work...thanks again.
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 27, 2017, 02:17:05 PM Last edit: September 27, 2017, 02:54:09 PM by paraboul |
|
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
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 02:54:23 PM |
|
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?
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 27, 2017, 03:40:06 PM |
|
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.jpgThanks and how can I do this? and test it? http://php.net/manual/en/function.error-reporting.phpIf it's just for file_get_contents, add a @ in front of the call.
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 04:05:48 PM |
|
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.phpIf 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"
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 27, 2017, 05:59:04 PM |
|
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
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 27, 2017, 07:03:16 PM |
|
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 I have put this: ini_set('display_errors', 'off'); error_reporting(0);
But I do not see a difference. about the @ I have not yet foud.
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 28, 2017, 07:08:06 PM |
|
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 I have put this: 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)
|
|
|
|
PrivCoin
|
|
September 29, 2017, 03:03:14 AM |
|
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 I have put this: 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);
|
|
|
|
paraboul
Newbie
Offline
Activity: 29
Merit: 0
|
|
September 29, 2017, 08:53:54 AM |
|
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.
|
|
|
|
winspiral (OP)
Legendary
Offline
Activity: 1778
Merit: 1026
Free WSPU2 Token or real dollars
|
|
September 29, 2017, 01:19:17 PM |
|
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.phpI 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...
|
|
|
|
|