用PHP以编程方式浏览远程网站

How do I go about programmatically use PHP to access a secure site of a website and pull an image? There is a website that I can login with my username/password. Once logged in, I then have to go to a few different pages before the image is available for download. I am trying to download a POD (Proof of Delivery) image from a carriers website.

Can this be done with CURL?

Unfortunately, I cannot access the image directly because: a) it is in a password protected area b) I think there are session variables being set as you browse, as if i browse to the POD of the consignment, there is no request variables added to the image, so I am thinking the previous page must set a session variable to say "this is the consignment I am currently looking at".

Also- is there any ethical restrictions you guys can see in doing this? If I company lets you login to their website, I can't see why they would care if you are doing it physically or programmatically.

I often use SimpleTest's PHP Scriptable Web Browser for such tasks.

Regarding your "ethical" question, if you're not breaking any laws and getting the information for personal purposes, nobody should care. Just don't abuse it.

If you can't access it because it's behind a password, what makes you think you can write an automated script to get it?

A program of this kind can only do as much as you can, but with less effort when used repeatedly.

If all you need is "a" POD, then you will be wasting a LOT of effort trying to get a program to do it for you.

Personally, I care a lot if someone's using a bot to access my site, but that's a biased opinion because I make games and so botting is always cheating. That said, most site owners would probably disapprove of needless botting, with search-spiders being an obvious exception.

Yes, you should use CURL. Probably they use redirect. CURL doesn't handle it automatically, as long as you don't use CURLOPT_FOLLOWLOCATION.