0

Gone through related posts and found turning allow_url_include will does the trick. However when I did this :
remote file file.php at http://www.courierscripts.com

$content = file_get_contents('http://www.courierscripts.com/folder/file.php'); 

on my functions.php, was not able to use the functions of file.php. I also don't want to change my file.php to file.txt because everyone can see it.

Any other way?

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
  • 1
    http://stackoverflow.com/questions/3488425/php-ini-file-get-contents-external-url – Dirk Jan Mar 08 '16 at 12:35
  • If we do this can we use remote file http://www.courierscripts.com/folder/file.php as local file file.php ? –  Mar 08 '16 at 13:15
  • Just to be clear: What you're asking for is about as bad as it gets in terms of bad coding practice. It is bad for performance reasons, bad for security reasons, bad for system design reasons. Do not do it. Even if you can find a way to get it working, I'll repeat: Do Not Do It. – Simba Mar 10 '16 at 14:40

1 Answers1

0

If the file is on the same server, use absolute or relative path to it, not an url. Otherwise:

Short answer:

No, it's not possible.

Long answer:

Actually possible with conditions but I bet you won't like them.

It's obviously impossible if you don't have access to the target server (otherwise storing passwords in php config files like Wordpress does would be just one big security flaw).

First of all, file_get_contents returns a string. So you could eval it, but eval is very bad (you can search SO for the clues why).

OK, suppose you agree to eval what's coming from that server even after considering that someone might change the code and do whatever he wants on your machine. BUT you make an http request that is handles by the server (Apache, Nginx or whatever else).

The server knows that *.php files should not be handles as static files. For example, fastcgi. You can turn that off, for example, with RemoveHandler in Apache. But that would let everyone see the source code of files you expose this way.

So, after removing handlers and evaling the result, you could get the result. But be ready that someone you work with will punch you in the face for doing that ;)

UPD

For code sharing, use Composer to create a package and use it as a dependency.

Community
  • 1
  • 1
Alexander Mikhalchenko
  • 4,525
  • 3
  • 32
  • 56