How to automate http authentication url from php

if you have to download a file from a web address that would trigger a username and password window (http authentication), then here is the trick

$downloaded_content = file_get_contents("http[s]://yourusername:yourpassword@thefiledownloadurl");
file_put_contents('/tmp/tempholder.csv', $downloaded_content);

The line of interest would be the first one with file_get_contents.
Once you get the content, you can perform a lot of things, either use the content as it is, or copy it to file using file object or just simply transfer the content to other file as the example depicts..