How to set PHP_AUTH_PW in php curl

How to set PHP_AUTH_PW and PHP_AUTH_USER parameters in php curl.

At the end of the server, check it:

if (! Iset ($ _ SERVER ['PHP_AUTH_PW'])) {print "Authorization error"}

Any help would be appreciated

thanks

+4
source share
1 answer

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

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

and in PHP you set two parameters for your curl connection ($ curl_conn):

 curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl_conn, CURLOPT_USERPWD, 'username:password'); 
+9
source

Source: https://habr.com/ru/post/1336760/


All Articles