Advertisement
Guest User

PHP json

a guest
Nov 23rd, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. header('Content-type: application/json');
  3. ini_set("display_errors", false);
  4. $user = $_GET['user'];
  5. $arr = array("name"=>$user, "agent"=>"minecraft");
  6. $data = json_encode($arr);
  7.  
  8. $ch = curl_init('https://api.mojang.com/profiles/page/1');
  9. curl_setopt($ch, CURLOPT_POST, true);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  12. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  13. 'Content-Type: application/json',
  14. 'Content-Length: ' . strlen($data))
  15. );
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  17.  
  18. if(!($res = curl_exec($ch))) {
  19. echo('[cURL Failure] ' . curl_error($ch));
  20. }
  21.  
  22. curl_close($ch);
  23. echo $res;
  24. $username = json_decode($res, true);
  25. echo 'UUID: ' . $username->profiles[0]->id;
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement