Belgin Fish
Belgin Fish

Reputation: 19837

Retrieve file from url with autorization PHP

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 :)

Upvotes: 0

Views: 98

Answers (3)

Wrikken
Wrikken

Reputation: 70480

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

Upvotes: 3

Brent Baisley
Brent Baisley

Reputation: 12721

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.

Upvotes: 2

Amy B
Amy B

Reputation: 17977

file_put_contents('where to put it', file_get_contents('http://username:[email protected]/video'));

Upvotes: 3

Related Questions