0

Possible Duplicate:
including php file from another server with php

Every php programmer knows that the include() function of php is used to include a php file in another php file,but i want to know that is it possible to including a php file which resides in a different server.i.e. suppose i want to include a.php in b.php now suppose a.php and b.php resides in different server,in that case is it possible to include a.php in b.php?

Community
  • 1
  • 1
Sahasrangshu Guha
  • 672
  • 2
  • 11
  • 29

5 Answers5

2

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 a URL (via HTTP or other supported wrapper - see Supported Protocols and Wrappers 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.

With the power vested in me by 60.2k rep, I recommend you don't do this.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
2

I think you're seeing it from a wrong point of view. Most of the time you'll don't want to merge PHP files from different servers - for this, you have other technologies used to do that.

If you want to include a file from another server, and fetch the source code, you'll need a permission to do so and, let's say once you have a permission you can simply copy the source code to your server.

However, if you want to communicate between the files that's not the method. You can use AJAX, JSON and GET parameters to communicate (and probably many other methods).

Nadav S.
  • 2,429
  • 2
  • 24
  • 38
0

yes it is possible, but may be a bad decision ? If anything happens to b.php a.php's server is also comprimised. file_get_contents and exec() would allow you to do it. Is it important that it runs or do you just need output ?

exussum
  • 18,275
  • 8
  • 32
  • 65
0

As the others said, no, not possible. (Else you would be able to read anyone's serverside code)

It would be better in every view to use something like SOAP or REST to communicate with other machines.

Martin
  • 1,488
  • 1
  • 13
  • 16
0

Using a PHP file that is on a separate server would cause you many problems. If your server can access the code of a PHP file, then so can anyone else who wishes to browse to that URL.

Anything a server can see that is EXTERNAL, anyone can see.

Adam
  • 1,214
  • 13
  • 23