0

How would I get an external PHP file as string without executing it. I've tried

$content = file_get_contents($url);

But it returns the results of the php file not the script itself. I've read that using a relative path would do what I want, but that's not viable as I'm trying to access a script from a different site. I do have FTP access, but I am hoping there's a simpler method.

7
  • 4
    You will not get the PHP-contents of a different site using file_get_contents, because the file will be rendered by the external server before serving it to you. Commented Oct 26, 2015 at 21:43
  • 2
    There would be major security issues if getting the PHP contents of an externally-hosted file without some kind of authentication were possible... Commented Oct 26, 2015 at 21:44
  • 3
    You would have to get the content via FTP or some other non-HTTP protocol that would not execute the requested URL via web-server (i.e. execute the script). That being said. I would be concerned over this sort of architecture. Why are you planning to do this? Commented Oct 26, 2015 at 21:44
  • 1
    this is prevented for good reason! Imagine if this worked, it would be a security nightmare. Commented Oct 26, 2015 at 21:45
  • 3
    Why do you need to get an external PHP file. This may be an X-Y problem Commented Oct 26, 2015 at 21:47

1 Answer 1

1

If you have FTP access, I'm not sure how much simpler you can get.

$url = "ftp://user:[email protected]/file/path";
$content = file_get_contents($url);
Sign up to request clarification or add additional context in comments.

Comments

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.