download data from other sites

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

download data from other sites

Post by psychotomus »

How can I download web pages with php? I want to download the web pages using php then display them. Anyone know how?
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

nevermind. found out fopen can do it.
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

keep in mind that you only see html part, not the php codes of a page.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

how can I see all?
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

you can't unless you want to hack them or write them a nice letter asking for the code.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

psychotomus wrote:how can I see all?
You can't ever view the PHP if PHP is installed correctly and the script is served by HTTP.

Also, fopen() wont work all the time... some sites will reject you for not sending the User-Agent: header.

As I have found froma recent project, fsockopen() does the job much better and you can spoof the script as whatever browser you like....

Even better - use cURL :wink:
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

cant i connect to the site as if my php script was a browser and get all the contents then display it?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

psychotomus wrote:cant i connect to the site as if my php script was a browser and get all the contents then display it?
You still wont get the PHP code...
The PHP will have been parsed by the time it reaches your browser.

In terms of making the script look like a browser, cURL does it pretty well. Next inline, fsockopen() with the correct headers
Post Reply