tags:

views:

34

answers:

3

Hi, I'm currently trying to grab a file from an external url that has an authorization box that pops up (like the default one asking for a username and password)

How can I have a script get the contents of the page (it's a video), save it to a directory and handle the authorization (i have a username and password)

Thanks :)

+3  A: 
file_put_contents('where to put it', file_get_contents('http://username:[email protected]/video'));
Coronatus
if it's a web page, you need to emulate a POST, which file_put_contents won't do.
Brent Baisley
@Brent - `file_put_contents` is for writing locally, nothing to do with any HTTP methods.
Coronatus
+2  A: 

You don't need to download the page, just check what is being submitted to the web server. Chances are it's just a POST. It may have some additional checks (i.e. checksum) which may need to be scraped from the page.

You can use the HTTP Headers plugin for Firefox to see how the browser is communicating with the server. You then just need to emulate that transaction. It is likely a POST, which is easy to do with CURL.

I don't think file_put_contents will work since it doesn't do an http POST.

Brent Baisley
+3  A: 

In a word, look at curl: http://php.net/curl, for all you posting/logging in/cookies/session needs in HTTP country.

Wrikken