Are there any alternatives to using CURLOPT_HTTPHEADER & CURLOPT_USERPWD for supplying Basic Authentication for cURL PHP?
I have a super long password, so CURLOPT_USERPWD wont work as it truncates at 256 characters.
curl_setopt($data, CURLOPT_USERPWD, $username . ":" . $password);
And I would like to stay away from using CURLOPT_HTTPHEADER for security reasons.
curl_setopt($data, CURLOPT_HTTPHEADER, "Authorization: Basic " . base64_encode($username . ":" . $password));
Any alternatives?
To send basic auth credentials with Curl, use the "-u login: password" command-line option. Curl automatically converts the login: password pair into a Base64-encoded string and adds the "Authorization: Basic [token]" header to the request.
Sending the Bearer Token with a Curl POST request is similar to sending the Bearer Token with a Curl GET request. POST data is passed with the -d command-line option, and the authorization header and the bearer token are passed with the -H command-line option.
curl_setopt — Set an option for a cURL transfer.
curl_exec(CurlHandle $handle ): string|bool. Execute the given cURL session. This function should be called after initializing a cURL session and all the options for the session are set.
What makes you think CURLOPT_HTTPHEADER
is disabled for security reasons?
It accepts an array rather than a string. Try this instead:
curl_setopt($data, CURLOPT_HTTPHEADER,
array(
"Authorization: Basic " . base64_encode($username . ":" . $password)
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With