downloading source code of an external website

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
bucz
Forum Newbie
Posts: 6
Joined: Mon Aug 03, 2009 2:49 am

downloading source code of an external website

Post by bucz »

hello,

my question is: how, using php, download source code of an external webpage? i have an url http://www.example.com/index.php?show=0123 and if I pass it to the file() function, it kicks back an error. I belive that it is because i use arguments in url (that are nececitary). is there something similat to linux

Code: Select all

wget -O - http://www.example.com/index.php?show=0123
?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: downloading source code of an external website

Post by onion2k »

To do that in PHP the URL wrapper option in PHP.ini has to be enabled .. if it is then file(), file_get_contents(), etc will all work. If it's not then you could alternatively use shell() or exec() with wget.

It's obvious, but in case you're not aware it will download the HTML source, not the PHP/Perl/ASP/whatever. You can't get that.
bucz
Forum Newbie
Posts: 6
Joined: Mon Aug 03, 2009 2:49 am

Re: downloading source code of an external website

Post by bucz »

thanks for a fast response

well, it is not my server and i am afraid that i cannot play with php.ini configuration... and what if i cannot exec anything as well? is there any php procedure that would work here?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: downloading source code of an external website

Post by onion2k »

bucz wrote:well, it is not my server and i am afraid that i cannot play with php.ini configuration... and what if i cannot exec anything as well? is there any php procedure that would work here?
You could try curl(), or fsockopen(), but they're both going to be a lot more complicated than things like file_get_contents(), and they probably won't work if the server is locked down properly.
Post Reply