php curl basic auth

Solutions on MaxInterview for php curl basic auth by the best coders in the world

showing results for - "php curl basic auth"
Eustace
31 Jan 2017
1<?php
2ini_set('display_errors', 1);
3ini_set('display_startup_errors', 1);
4error_reporting(E_ALL);
5$host = 'http://google.com';
6$message = 'Test message';
7$phone = '998999999';
8$username = 'username';
9$password = 'password';
10$post = [
11    "messages" => [
12        [
13            "recipient" => $phone,
14            "message-id" => "itrust" . strval(time()),
15
16            "sms" => [
17                "originator" => "3700",
18                "content" => [
19                    "text" => $message
20                ]
21            ]
22        ]
23    ]
24];
25$payloadName = json_encode($post);
26
27$ch = curl_init($host);
28curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
29curl_setopt($ch, CURLOPT_HEADER, 1);
30curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
31curl_setopt($ch, CURLOPT_TIMEOUT, 30);
32curl_setopt($ch, CURLOPT_POST, 1);
33curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadName);
34curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
35$return = curl_exec($ch);
36curl_close($ch);
37
38echo '<pre>';
39var_dump($return);
40echo '</pre>';
41
Brandon
21 Mar 2019
1<?php 
2define('OAUTH_TOKEN_URL','https://api.example.com/oauth/token'); // replace with according to documentation
3$url ='' ; // your redirect url
4$client_id = ''; // your client id from api
5$client_secret = ''; /your client secret from api
6// if api require client id and client secret in paramters then below other wise
7$data = "grant_type=authorization_code&code=".$_GET['code']."&client_id=".$client_id."&client_secret=".$client_secret."&redirect_uri=".$url;
8
9$headers = array(
10        'Content-Type:application/x-www-form-urlencoded',
11);
12
13// if api requires base64 and into -H header than 
14
15//$data = "grant_type=authorization_code&code=".$_GET['code']."&redirect_uri=".$url;
16//$base64 = base64_encode($client_id.":".$client_secret);
17
18//$headers = array(
19 //   'Content-Type:application/x-www-form-urlencoded',
20  //  'Content-Type:application/json',
21   // 'Authorization: Basic '. $base64
22// );
23
24$response = curlPost($data,$headers);
25print_r($response);
26
27function curlPost($data,$headers){
28    
29    $ch = curl_init();
30    curl_setopt($ch, CURLOPT_URL,OAUTH_TOKEN_URL); 
31    curl_setopt($ch, CURLOPT_POST, 1);
32    curl_setopt($ch, CURLOPT_POSTFIELDS,$data);  //Post Fields
33    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34    
35    
36    
37    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
38    
39    $server_output = curl_exec ($ch);
40    
41    return $server_output;
42    curl_close ($ch);
43    
44}
queries leading to this page
php curl bearer token examplecurl oauth2 php tokencurl post example php with basic auth headerget request with basic auth php curlbasic authentication php curlbasic auth curl phpbasic auth in php curlcurl php with authenticationcurl post request with bearer token phpcurl authentication phpphp curl request tokenphp curl login and get tokensend user data using curl in phphow connect to api from php curl with access tokenphp send post request curl function authorization headercurl php authorizationcurl authentication header phpphp curl add basic authphp curl authenticationphp curl basic authphp curl get with tokenphp curl post basic authphp curl add basic auth headerbasic authentication php curl gethow to send basic auth in curl phpphp curl auth basichow take access token in curl with phpphp curl authcurl basic authentication example phpphp curl header basic authcurl basic auth phpphp curl get request with basic authenticationcurl post auth token phpphp curl basic authenticationcurl php post with authphp curl apache authtype basiccurl token authorization in phpphp curl apache basic authenticationphp curl basic authorization basic auth php curlphp curl get request with authenticationphp curl with auth headerbearer token in curl phpphp curl basic auth example postphp curl request with basic authphp curl get request basic authphp curl set authorizationcurl php basic authphp curl add authorization headerphp curl oauth2 basic authphp basic auth curlcurl for authentication phpphp curl basic auth