I had to get a page that is in a password protected directory.
First I used php file_get_contents() which is always my first solution for accessing remote pages. But many web servers disable allow_url_fopen in php config. So curl is the ultimate solution.
Curl has an option called CURLOPT_USERPWD that allows to add the user name and password along with the request. A sample code may be as following:
<?php
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, "http://domain/passdprotected/filename");
curl_setopt($curlObj, CURLOPT_USERPWD, "username:password");
curl_exec($curlObj);
curl_close($curlObj);
?>
Hope this helps!!

