-4

I'm trying to use the mojang api to retrieve a users Minecraft UUID from their Username this is what i have:

//Get Player UUID from name
$uuid = "Error obtaining uuid";
$json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' + $_GET['name']);
$obj = json_decode($json);
$uuid = $obj->id;

The variable $uuid contains null and im not sure what im doing wrong i made sure i set the $_GET parameters by going to player.php/?name=_Joosh but still nothing?

Bijan
  • 7,737
  • 18
  • 89
  • 149
Joosh
  • 136
  • 1
  • 9
  • Is there anything on `$json`? Please, `var_dump($json)`, [edit](http://stackoverflow.com/posts/34486105/edit) your question and post the updates... – FirstOne Dec 27 '15 at 23:50
  • @FirstOne returns: bool(false) – Joosh Dec 27 '15 at 23:52
  • 2
    Please, check if [allow_url_fopen](http://stackoverflow.com/questions/13433660/how-to-check-if-allow-url-fopen-is-enabled-or-not) is enabled. Also, PHP uses `.` to [concat string](http://php.net/manual/en/language.operators.string.php). – FirstOne Dec 27 '15 at 23:58
  • Thank you @FirstOne i was mixing java with php and using + that was my issue, thank you. – Joosh Dec 28 '15 at 00:12
  • So, the problem was just with the concat part? I mean, is this solved? – FirstOne Dec 28 '15 at 00:13
  • If this is solved, please answer your own question below with the working example and mark it as accepted. – Will Dec 28 '15 at 00:27
  • @joosh, Your concatenation operator is wrong. refer my answer for working sample – Venkat.R Dec 28 '15 at 01:01

1 Answers1

1

You have to use dot opearator for concatenation not plus. Try the below snippet.

//Get Player UUID from name
$name = 'john';
$uuid = "Error obtaining uuid";
// Tested with simple variable
// $json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $name);
$json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $_GET['name']);
$obj = json_decode($json);
$uuid = $obj->id;

print $uuid;
worldofjr
  • 3,868
  • 8
  • 37
  • 49
Venkat.R
  • 7,420
  • 5
  • 42
  • 63