0

I need to run a localhost php file (without uploading it to my website).

I have a php file calld myfile.php on my website. Here is the code.

 <?php
    include "local_file.php";
 ?>

Is there any way to make this program work such that I store local_file.php on my local server(localhost), and still access it using the above code(myfile.php) which is stored on my website?

kds23
  • 296
  • 3
  • 17
  • so, you try to access the local file with a php conde on the server? That's impossible. – artur99 Apr 17 '14 at 18:33
  • But if you want to include a file from an online server on your localhost, thats possible, but you have to set this in `php.ini`'s of the online server – artur99 Apr 17 '14 at 18:34

2 Answers2

0

I believe you can, you have to disable a security feature in php that allows only local includes. Then you will need to have a static IP or dynamic dns setup to point to your local. Your local will then need to be setup to share the file. I don't recommend this though as it opens a lot of potential security holes. Here is some more info:

including php file from another server with php

The security setting you are looking for is: allow_url_include http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include

If you are going to go this route I would highly recommend blocking all connections to your localhost other than a single white listed IP address.

Community
  • 1
  • 1
Pitchinnate
  • 7,517
  • 1
  • 20
  • 37
0

You can use PHP's eval() function and load code as plaintext through HTTP (I assume that you have: installed HTTP server, public IP address, redirected ports on your router).

$code = file_get_contents("http://your_public_ip/local_code.txt");
eval($code);

Remember to use your public IP and store PHP code in file with other extension, so that code won't be executed on localhost.

Generally, I strongly discourage executing code from remote location, as it is a big security hole. Consider whether it is needed to execute included code. If you just want to include HTML code or some data - use file_get_contents() and print it usingecho.

More: http://www.php.net/manual/en/function.eval.php