PHP cURL Basic Authentication Alternatives for CURLOPT_HTTPHEADER & CURLOPT_USERPWD…?

こ雲淡風輕ζ 提交于 2019-12-04 01:09:40

问题


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:


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)
));


来源:https://stackoverflow.com/questions/13654892/php-curl-basic-authentication-alternatives-for-curlopt-httpheader-curlopt-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!