0

I have a file located on my server and I want to remotely access that file from another server and execute source code of the file from another PHP file located on the another server.

I have had a look at “File_get_contents” however this only obtains the content displayed by that PHP file, as can be seen below.

So therefore is it possible for a PHP file from an external server to read the source code of the PHP file located on my server and execute the commands on the external server?

1 Answer 1

1

You can use an extension other than .php for the source file, then use file_get_contents (or similar) to retrieve the contents.

Not using the php extensions will prevent PHP from parsing it as code, and just send it over as text instead.

However, that will also make the source readable to anyone who navigates to the file in a browser, as well as introducing a possible major vulnerability. You should look into why this is necessary and if it can be avoided somehow (perhaps calling the file on the other server with GET or POSTed parameters).

Sign up to request clarification or add additional context in comments.

4 Comments

I second this. To actually include the file, you need to have the fopen_wrappers enabled and then you just require(), require_once(), include() or include_once() like you would with a local file but passing the URL as argument.
@Raphael Schweikert If you have an example on this or anything other information I would be grateful.
require("http://yourdomain/yourfile.php") is the general idea. What are you trying to do, and why does this one file need to be on another server?
To use requireand its variants for this, you need to enable both the allow_url_include and allow_url_fopen in your php.ini config file. Note that these settings can not be set in your .htaccess file for security reasons. See PHP Filesystem Runtime Configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.