include php function on different server

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
bertsmilsky
Forum Newbie
Posts: 13
Joined: Fri Jul 18, 2008 10:23 am

include php function on different server

Post 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?
Last edited by bertsmilsky on Fri Jul 18, 2008 11:18 am, edited 1 time in total.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: include php function on different server

Post 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...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: include php function on different server

Post 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.
Post Reply