PHP cURL Basic Authentication Alternatives for CUR

2020-03-17 07:46发布

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?

1条回答
迷人小祖宗
2楼-- · 2020-03-17 08:04

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)
));
查看更多
登录 后发表回答