Page 1 of 1

include php function on different server

Posted: Fri Jul 18, 2008 10:54 am
by bertsmilsky
I want to protect my source code in the cms i have written by including files on a different server to my clients'. when i include a file on a different server i cannot get the function on that file to work. see the following:

File on server 1: http://www.example1.com/server1.php

Code: Select all

<?php
$path = "http://www.example2.com/";
require $path."server2.php";
TestFunction();
?>
File on server 2: http://www.example2.com/server2.php:

Code: Select all

<?php
function TestFunction(){
  echo "Test works";
}
?>
When i call http://www.example1.com/server1.php i get the following error:

Fatal error: Call to undefined function: TestFunction()

Is there a way i can do this? or any suggestions on how to protect my logic simply and easily?

Re: include php function on different server

Posted: Fri Jul 18, 2008 11:01 am
by alex.barylski
You can't do what you are trying to do...

Well you could maybe include a remote file using ftp wrapper in the include but that wouldn't really protect your code.

Your best bet would be to use SOAP or similar technique...

Re: include php function on different server

Posted: Sat Jul 19, 2008 2:15 am
by Chris Corbyn
The reason it's not working is because when PHP tries to download the file over HTTP, the remote server is parsing the PHP first as if it's being requested to serve up a web page. Try opening that URL in your web browser... you'll be what the other script is getting -- nothing.