displaying contents of another page on the current page

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
ethicalhacker
Forum Newbie
Posts: 2
Joined: Tue Mar 06, 2007 10:30 pm

displaying contents of another page on the current page

Post 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
Last edited by ethicalhacker on Wed Mar 07, 2007 12:00 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I am guessing that you do not have permission to scrape that page.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
ethicalhacker
Forum Newbie
Posts: 2
Joined: Tue Mar 06, 2007 10:30 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Xoligy
Forum Commoner
Posts: 53
Joined: Sun Mar 04, 2007 5:35 am

Post 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).
Post Reply