www.pokeroconnor.com


Http Authentication with curl_setopt

April10

If you want to access a web page that requires http authentication via a php script, a very handy way to do it is the following:

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, ‘http://my.url.com/password.asp’); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 

curl_setopt($ch, CURLOPT_USERPWD, ‘user_name:password’);

 

$data = curl_exec($ch); 

curl_close($ch);

 

echo “<pre>”; 

print_r($data); 

echo “</pre>”;

//
posted under php

Email will not be published

Website example

Your Comment: