noru
noru

Reputation: 1

Run base php code on multiple domains

I need a solution to run some PHP code on multiple domains. The domains are hosted on different servers, and the base PHP code isn't on any of them, let's say a dev server.

All I could come up with was using file_get_contents on a file hosted on the dev server, and running that code with eval. So on every domain i have an index.php file with :

error_reporting(0);
$code = file_get_contents("http://www.mydevserver.com/main.php");
if ($code === false) {
// treat error
die();
} else {
// run code
eval($code);
}

So far I have only one file with a few functions in it, but things could get more complex in the near future. And I have to mention I'm not only handling data, but also presentation, so I don't know if an API could help.

Any insights on how I could do this better ?

I have to point out that unfortunately all I have is FTP access on the remote servers and I can't get anything else.

Thank you !

Upvotes: 0

Views: 452

Answers (5)

bradym
bradym

Reputation: 4961

Come up with a folder structure and file naming scheme that will be consistent on all of these servers. Once you've done that, writing a script to FTP the file to all of the servers at once would be very easy.

Getting and executing code from a remote server is asking to be hacked.

Upvotes: 0

wimvds
wimvds

Reputation: 12850

Just include or require the damn code (ie. either a script that will spit out the necessary PHP code or a plain text file containing the PHP source code), but I wouldn't recommend doing this (in fact I would urge you to rethink this choice you made). This will only work if URL wrappers are enabled of course.

Upvotes: 1

Alin P.
Alin P.

Reputation: 44386

That file_get_contents will get the return of your PHP script, not the source code.

Please rethink your need to do this and if it really is necessary to load dynamic PHP consider using a secure connection, maybe SFTP.

Also as everyone here suggests, I also recommend using version control for this and only deploying stable versions.

Upvotes: 0

Wrikken
Wrikken

Reputation: 70540

Options:

  • Store the code locally, keep in sync with either version control checkouts or rsync's.
  • Create an NFS of SSHFS mount (or any mount that's workable), use those files there.

Upvotes: 0

reko_t
reko_t

Reputation: 56460

You should really host the files where-ever they're run in. What you're doing now is very insecure for multiple reasons. If you're concerned about keeping the code in sync, setup subversion, or similar source version control system, then syncing the code between different servers is as simple as updating the local repository.

Upvotes: 5

Related Questions