PHP curl Http authentication header from Client

PHP curl Http authentication header from Client

Today, We want to share with you PHP curl Http authentication header from Client.
In this post we will show you HOW TO use Basic Authorization with PHP cURL, hear for PHP: HTTP authentication with PHP we will give you demo and example for implement.
In this post, we will learn about Set Http authentication header from Client — PHP / CURL with an example.

SMSpay Payment Gateway

SMSpay Payment Gateway used for to WooCommerce allows Norwegian merchants used to accept payments via mobile SMS on WooCommerce, using the Basic SMSpay.io service.

Invalid signature received for JSON Web Token validation

{“statusCode”:401,”error”:”Unauthorized”,”message”:”Invalid signature received for JSON Web Token validation”,”attributes”:{“error”:”Invalid signature received for JSON Web Token validation”}}

  PHP Ternary shorthand If/Else Examples

//ssl verifypeer
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Set the simple content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

Sendipakainfo Auth in headers PHP curl : SMSpay documentation

<?php
session_start();
//API Url
$url = 'http://api.smspay.devz.no/v1/login';

//Initiate cURL.
$ch = curl_init($url);

//The JSON data.
$jsonData = array(
    'user' => '[email protected]',
    'password' => 'pakainfo******'
);

//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//ssl verifypeer
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Set the simple content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

//Execute the request
$result_data=curl_exec($ch);

// close cURL resource, and simple free up system resources
curl_close($ch);
echo "<pre>";
print_r($result_data);
echo "</pre>";
?>

PHP – Creating OAuth Authorization Header

<?php
$obj = json_decode($result_data, TRUE);
$access_token=$obj['token'];
$_SESSION['name']=$access_token;
$mid=$obj['merchantId'];
$access_token=$_SESSION['name'];

echo "<br/>";

$url="http://api.smspay.devz.no/v1/payments";

    $ch = curl_init();  
	$jsonDatapayements = array(
	
		'phone' => '+9198985698',
		'currency' => 'USD',
		'invoice' => '011',
		'shippipakainfo'=>'12500',
		'merchant' => $mid,
		'item_number_1'=>'985',
		'item_name_1'=>'Tools',
		'amount_1'=>'3585',
		'quantity_1'=>'10',
		'shippipakainfo_1'=>'148'
		);
	$jsonDatapay = json_encode($jsonDatapayements);
    curl_setopt($ch,CURLOPT_URL,$url);
	
	curl_setopt( $ch, CURLOPT_POST, count( $jsonDatapayements ) );
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	
	$header   = array();
	$header[] = 'Authorization: Bearer ' . $access_token;
	$header[] = 'Content-Type:  application/json ';
	
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDatapay);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $output=curl_exec($ch);
	
    curl_close($ch);
	
	echo "<pre>";
	print_r($output);
	echo "</pre>";
?>

View More..

  PHP Upload File Size Limit

We hope you get an idea about PHP curl Http authentication header from Client
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.