Using Curl With PHP to Retrieve Pages With Basic Authentication

To retrieve a particular page from another web site using basic authentication, use this PHP script:

$path = $_GET['path'];
$username = "username";
$password = "password";
$uri = "$path";
$ch = curl_init($uri);
curl_setopt_array($ch, array(
    CURLOPT_USERPWD=> "$username:$password",
    CURLOPT_VERBOSE     => 1
$out = curl_exec($ch);
echo $out;

Use the path of the file as the parameter. In this case you could retrieve an HTML file by a URL like this:

Beware, because this isn’t particularly secure, but it is a way to do some quick and dirty proxy for servers with known users and where the script is hosted on a very secure site, but is consuming from another site that has lighter security requirements, like basic authentication.