Including from another server

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
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Including from another server

Post by f1nutter »

Hi folks,

I am having trouble including a file from another server. I have permission from a news site to include there news script, but when I try to include it, it doesn't work.

Code: Select all

<?php
 include('http://www.newssite.com/news.php')
?>
Local includes are OK, but not from external sites. I have tried changing the php.ini file but cannot seem to get the settings right. Am I missing something?

Thanks.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

From the manual....
If "URL fopen wrappers"
are enabled in PHP (which they are in the default configuration),
you can specify the file to be included using an URL (via HTTP or
other supported wrapper - see Appendix I for a list
of protocols) instead of a local pathname. If the target server interprets
the target file as PHP code, variables may be passed to the included
file using an URL request string as used with HTTP GET. This is
not strictly speaking the same thing as including the file and having
it inherit the parent file's variable scope; the script is actually
being run on the remote server and the result is then being
included into the local script.
The manual is your friend. :twisted:

Cheers,
BDRK
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

I've read the manual, and already set allow_url_fopen to On. (It was set like that as the default)

If I read in a file as a URL it works, parsing the file and printing the output

Code: Select all

print_r (file('http://www.someothersite.com'));
but including doesn't work

Code: Select all

include('http://www.someothersite.com');
Any suggestions?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Which OS and PHP version are you using?
PHP Man Page - include() wrote:Windows versions of PHP prior to PHP 4.3 do not support accessing remote files via this function, even if allow_url_fopen is enabled.
Mac
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

Well done Mac!

I'm using PHP 4.2.3 on Windows 98. I downloaded the help file for that version, and guess I should have checked the PHP site for up to date stuff!

I then started wondering why my host site supports it, yet they are using 4.1.2, but thats Linux!

Problem solved, job done!

Cheers.
Post Reply