PHP Curl Request with Username and Password Example
This article is focused on php curl request with username and password. if you want to see example of php curl basic auth username:$password then you are a right place. you can understand a concept of php curl authorization username:password. you can see php curl basic auth example. you will do the following things for php curl basic auth username password.
In this example, we will use CURLOPT_HTTPAUTH and CURLOPT_USERPWD to pass username and password for authorization. so let's see bellow simple example code here:
Example:
<?php
$username = 'username';
$password = 'password';
$URL = 'https://api.mywebtuts.com/api/users';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
?>
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Curl PUT Request Example Code
- PHP Curl Delete Request Example Code
- PHP Curl POST Request with Headers Example
- PHP Curl Get Request with Parameters Example
- PHP Curl Request with Certificate (cert pem file option) Example
- Codeigniter Curl Post Request with Parameters Example
- PHP CURL Post Request with Parameters Example
- Laravel CURL Request Example using Ixudra/curl
- PHP Download File from URL using CURL Request Example
- How to Upload Image using jQuery Ajax in PHP?
- How to Find Day Name from Specific Date in PHP?
- How to Remove Null Values from Array in PHP?