llokely
llokely

Reputation: 93

Include external code in php

I need to include to my php script external php code which is situated for example by link http://site.com/code.php How could I do it? I tryed all ways which I found in internet but no one works. All methods are good to include text but not php script.

Upvotes: 2

Views: 1175

Answers (3)

Francis Lewis
Francis Lewis

Reputation: 8990

According to the PHP documentation (http://php.net/manual/en/features.remote-files.php) "As long as allow_url_fopen is enabled in php.ini, you can use HTTP and FTP URLs with most of the functions that take a filename as a parameter. In addition, URLs can be used with the include(), include_once(), require() and require_once() statements (since PHP 5.2.0, allow_url_include must be enabled for these)."

Upvotes: 0

Nanne
Nanne

Reputation: 64439

You can only include the code if it is served as text: otherwise everyone would be able to see / use your code.

So the options you have:

  • Get the file trough ftp and include it with include or require
  • Get the file in plaintext, by serving .php files on "site.com" as text. This is ofcourse not a good idea, as everyone could see your source from there.
  • Put the file on the same server as the script that wants to include it.
  • If you need just the file to be 'run', you can curl it. You won't get the source (cannot use its functions etc) but any actions it performs (make file? add something to the database) will be run.

Upvotes: 5

foxy
foxy

Reputation: 7672

It is not possible, unless you can get the source code to it (aka. its published somewhere or it is on a file system you can access).

Upvotes: 0

Related Questions