Guest User

HTTP BASIC AUTH using Curl

a guest
Apr 8th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. $url = 'https://[your-url-here]';
  4.  
  5. //Basic Auth
  6. $username = 'your_user_name';
  7. $password = 'SomePassWord';
  8. $str = $username . ":" . $password;
  9. $encoded = base64_encode($str);
  10.  
  11. // HTTP Header
  12. $accesstoken = $encoded;
  13. $headr = array();
  14. $headr[] = 'Accept: application/json';
  15. $headr[] = 'Authorization: Basic '.$accesstoken;
  16.  
  17. //cURL starts
  18. $crl = curl_init();
  19. curl_setopt($crl, CURLOPT_URL, $url);
  20. curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
  21. curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
  22. curl_setopt($crl, CURLOPT_HTTPGET,true);
  23. $your_reply = curl_exec($crl);
  24.  
  25.  
  26. ?>
Add Comment
Please, Sign In to add comment