-
Notifications
You must be signed in to change notification settings - Fork 0
/
Minecraft-UUID-Utils.php
57 lines (53 loc) · 1.56 KB
/
Minecraft-UUID-Utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
function getUUID($username) {
try{
if(strlen($username) >= 16)
return false;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,'https://api.mojang.com/users/profiles/minecraft/'.$username);
// Execute
$json=curl_exec($ch);
$data = json_decode($json,true);
return formatUUID($data['id']);
}catch(exception $e) {
echo $e->getMessage();
}
}
function getUsername($uuid) {
if(strlen($uuid) != 36 && strlen($uuid) != 32)
return false;
if(strlen($uuid) == 36) {
$uuid = deformatUUID($uuid);
}
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,'https://api.mojang.com/user/profiles/'.$uuid.'/names');
// Execute
$json=curl_exec($ch);
$data = json_decode($json,true);
return end($data)['name'];
}
function formatUUID($uuid) {
$uid = "";
$uid .= substr($uuid, 0, 8)."-";
$uid .= substr($uuid, 8, 4)."-";
$uid .= substr($uuid, 12, 4)."-";
$uid .= substr($uuid, 16, 4)."-";
$uid .= substr($uuid, 20);
return $uid;
}
function deformatUUID($uuid) {
$uuid = str_replace("-","",$uuid);
return $uuid;
}