Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. http://www.dyn-web.com/tutorials/php-js/json/decode.php
  2. https://stackoverflow.com/questions/12429029/php-get-values-from-json-encode
  3. https://stackoverflow.com/questions/20193575/fetch-json-data-using-php
  4. https://stackoverflow.com/questions/12429029/php-get-values-from-json-encode
  5. https://stackoverflow.com/questions/4433951/decoding-json-after-sending-using-php-curl
  6.  
  7. array(1) {
  8. ["login"]=>
  9. array(2) {
  10. ["error"]=>
  11. bool(false)
  12. ["user"]=>
  13. array(5) {
  14. ["br_code"]=>
  15. int(0)
  16. ["mem_id"]=>
  17. int(202)
  18. ["username"]=>
  19. string(8) "johndoe"
  20. ["email"]=>
  21. string(33) "johndoe@gmail.com"
  22. ["created_at"]=>
  23. string(19) "2017-08-07 15:35:39"
  24. }
  25. }
  26. }
  27.  
  28. <?php
  29. session_start();
  30.  
  31. $ch = curl_init('http://localhost/sample/login.php');
  32.  
  33. $username= $_SESSION["USERNAME"];
  34. $password= $_SESSION["PASSWORD"];
  35.  
  36. $credentials = [
  37. 'username' => $username,
  38. 'password' => $password
  39. ];
  40.  
  41. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  42. curl_setopt($ch, CURLOPT_POST, 1);
  43. curl_setopt($ch, CURLOPT_POSTFIELDS, $credentials);
  44. curl_setopt($ch, CURLOPT_USERNAME, "{$username}:{$password}");
  45. // execute!
  46. $response = curl_exec($ch);
  47. // close the connection
  48. curl_close($ch);
  49.  
  50. $obj= json_decode($response, true);
  51.  
  52. // echo $obj; // Notice: Array to string conversion in
  53.  
  54. // echo $obj[0]; // Undefined offset
  55.  
  56. // echo $obj->user; //Trying to get property of non-object in
  57.  
  58. var_dump($obj);
  59.  
  60.  
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement