Page 1 of 1

Including from another server

Posted: Sat Feb 22, 2003 10:42 am
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.

Posted: Sat Feb 22, 2003 11:19 am
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

Posted: Sun Feb 23, 2003 5:50 am
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?

Posted: Sun Feb 23, 2003 5:55 am
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

Posted: Sun Feb 23, 2003 6:23 am
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.