Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set PHP_AUTH_PW in php curl

Tags:

php

curl

How to set the PHP_AUTH_PW and PHP_AUTH_USER parameters in php curl.

At the server end its checking for:

if(!isset($_SERVER['PHP_AUTH_PW'])) { print "Authorization error" }

Any help would be appreciated

Thanks

like image 644
RJ. Avatar asked Jan 20 '23 16:01

RJ.


1 Answers

It is called basic-auth, and works with most browsers including curl on command line:

curl --user name:password http://www.example.com

and in PHP you set two options on your curl connection ($curl_conn):

curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl_conn, CURLOPT_USERPWD, 'username:password');
like image 86
Jan Avatar answered Jan 29 '23 12:01

Jan