Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote includes

Status
Not open for further replies.

skiflyer

Programmer
Joined
Sep 24, 2002
Messages
2,213
Location
US
I'm trying something simple, and it won't work... was wondering if it's just me, or some feature I can't find.

On my webserver I have a file, test.php.inc
Code:
<?php
echo "testing 1 2 3";
function testVal() {
  return 101;
}
?>
And then on my local machine...
Code:
<?php
include('[URL unfurl="true"]http://remoteserver/test.php.inc');[/URL]
echo testVal();
?>
And the output is
test 1 2 3
Warning: Call to undefined function: what() in script.php on Line 3

So it's obviouslly succesfully including the file as it does the echo, but the functions aren't available. Works fine for local files obviouslly, anyone know what may be going on?
 
I'm confused.

In your code, the function is called "testVal", yet the error you report refers to a function named "what".

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sorry, made a couple different tests on different machines to make sure I could replicate it, and I combined two windows when I made my post.

It's also a fatal error... here it is verbatim

Fatal error: Call to undefined function testVal() in C:\Program Files\Apache Group\Apache\htdocs\test\test.php on line 4

 
you can't do it in that way...

include('
the response will be the page test.inc.php *processed* by php, resulting in a html page.

you should be able to get the file via nfs or something else.

Cheers.
 
I would agree with that if I had named it test.inc.php, but since it's test.php.inc shouldn't it be fine?
 
Huh, guess I was wrong... .php.inc doesn't help.... plain old .inc does though, and lets me still include it over the http:// address.

Not sure why Apache thinks it's its business to be serving up .php.inc files specially, but at least that takes care of the problem. Thanks for pointing me the right way Chacalinc.
 
I got the same error but I think I understand why. The presence of "Testing 1 2 3" in the output had me going for a while.

When you include a ".php" file from a web server that has the capacity to pre-process PHP, the remote server does not send you the file -- it runs the file and sends you the output. Change file's extension to something the remote web server won't try to execute.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
ooooh... you are right!! I'm very sorry. I mistake the name... :(

did you try with include_once or require?

take a look to this extract from php.net


If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Appendix J 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 a 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.

 
Yeah, looks like we were all posting at once at the end there.

It works fine with a .inc, but not a .php.inc Seems apache is being greedy and serving those files up with PHP, a real pain in regards to leveraging some of my older function files, but at least I know what's happening now.
 
good! only one thing comes to my mind, are these .inc pages in a external web server? because anyone could go to the server and get the sources...

Just a comment.
 
Fine by me, I'm sharing out functions, if they want them, then take them.... that's actually my point in this case... I want to expose some functions to wide availability.

But in this case no, it's an intranet server. That is a good point, you're basically sharing out a text file at this point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top