How to Use Basic Authorization In PHP curl?

PHP 8 , PHP

Nicesnippets

503

30-07-2021


Hi Guys,

In this example, I will learn you how to use basic authorization in php curl.you can easy and simply use basic authorization in php curl

This example is focused on basic authorization in php curl. We will look at example of basic authorization in php curl. This post will give you simple example of basic authorization in php curl.

Example:


<?php

$url = "https://api.nicesnippets.com/api/users/10";

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(

"Accept: application/json",

"Authorization: Bearer {token}",

);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

//for debug only!

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);

curl_close($curl);

var_dump($resp);

?>

It will help you...