Are there any best practices for handling sensitive data like passwords in cURL requests in PHP?

When handling sensitive data like passwords in cURL requests in PHP, it is best practice to avoid hardcoding the password directly in the code. Instead, you can store the password in a separate configuration file outside of the web root and include it in your PHP script. This way, the password is not exposed in the code itself and reduces the risk of unauthorized access.

// config.php
<?php
define('PASSWORD', 'your_password_here');
?>

// request.php
<?php
include 'config.php';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.example.com');
curl_setopt($ch, CURLOPT_USERPWD, 'username:' . PASSWORD);
curl_exec($ch);
curl_close($ch);
?>