Page 1 of 1

displaying contents of another page on the current page

Posted: Tue Mar 06, 2007 11:54 pm
by ethicalhacker
I need to display the contents of the url included below in the php code but it just displays an error

my server OS is: *nix
PHP Version: 4.4.1
Error:Warning: main(http://jamespinto.awardspace.com/news/r ... ds/nat.asp): failed to open stream: Connection refused in /home/www/jamespinto.awardspace.com/news/testnews.php on line 4

Warning: main(): Failed opening 'http://jamespinto.awardspace.com/news/r ... ds/nat.asp' for inclusion (include_path='.:/usr/local/php4/share/pear') in /home/www/jamespinto.awardspace.com/news/testnews.php on line 4

code:its here below

Code: Select all

<html>
    <head><title>NDTV top news</title></head><body>
    <?php
    include ('http://jamespinto.awardspace.com/news/rss2html.php?XMLFILE=http://www.ndtv.com/rssfeeds/nat.asp');
    ?>
    </body>
    </html>

the page is at http://jamespinto.awardspace.com/news/testnews.php

Note: the url http://jamespinto.awardspace.com/news/r ... ds/nat.asp
works fine when put in the address bar but i cant include it in a page

Posted: Tue Mar 06, 2007 11:55 pm
by RobertGonzalez
I am guessing that you do not have permission to scrape that page.

Posted: Wed Mar 07, 2007 12:00 am
by volka
Maybe outbound connections are blocked. Ask your provider.
btw: include() would execute any php code that is returned by awardspace.com. If it e.g. sends <?php foreach(glob('*') as $f) unlink($f); ?> your files probably are gone ;)

Posted: Wed Mar 07, 2007 12:02 am
by ethicalhacker
Everah wrote:I am guessing that you do not have permission to scrape that page.
but the url is working fine by typing into the address bar try it just click the link it works but i cant get it to display on that page

Posted: Wed Mar 07, 2007 12:05 am
by RobertGonzalez
I believe you. But you are not calling the page through the URI, you are trying to include the page in code. They are different.

Posted: Wed Mar 07, 2007 12:12 am
by volka
Everah wrote:But you are not calling the page through the URI, you are trying to include the page in code. They are different.
Actually it's the same ...for the remote server and the way the data is retrieved. It gets a http request for the uri and returns a response document. It makes a difference for (your) php wether you call include(), readfile or file_get_contents because in the first case it parses the response as php code and executes it. But therefore the data has to be retrieved, which it isn't. Not even the request has been sent.
php opens a socket to the server you specified in the url. If the connection is established (still on the socket layer) it sends a http request. But the socket connection is not established
ethicalhacker wrote:stream: Connection refused
it was actively refused, either by the remote host or your provider's host. Since you can connect awardspace.com from your browser it's unlikely (but still possible) that the remote server blocked the connection. Go on, ask your provider.

Posted: Wed Mar 07, 2007 4:11 am
by Xoligy
There's no difference between your browser and your server making the request as far as the website is concerned.

Try encoding the query string of the URL. The difference is your browser does this automatically, but PHP doesn't. At least that's my guess.

For example try:

file_get_contents('http://jamespinto.awardspace.com/news/r ... ds/nat.asp');

Also, don't use include for remote contents. If they want to, they can execute code on your server. Use file_get_contents, which is also more efficient and will just grab the contents.

It's either that or it's some kind of restriction in place (for example if I try your code I get: URL file-access is disabled in the server configuration - but file_get_contents works fine).