Jump to content

including functions from another website


bushkilldogo

Recommended Posts

Hello, I am currently creating a few sites that I wish to include a set of functions hosted on a separate site so that I only have to update on one site instead of a few.

 

My problem is that when i try to include the file from the remote site, the functions are not read but everything else is...

 

ie...

 

remote file contents

-------------------

 

echo "TEST";

 

works when I use the include function but when i put it as a function...

 

function doTest() {

echo "test";

}

 

then call it on the main site...

 

<? echoTest(); ?>

 

i get "Fatal error: Call to undefined function"

 

 

how can i fix this?

 

Link to comment
Share on other sites

any plans to add this in php later?

 

I doupt it, imagine the security implications. Anyone would be able to include functionality from other peoples code base into there own sites.

 

The only real workaround I can see would be using nfs to mount the remote filesystems to a mountpoint on your servers.

Link to comment
Share on other sites

By making the file extension something that is not parsed by php, you could do this, but as thorpe has already written, it presents a huge security hole as anyone who finds the files can see the code and data they contain.

 

So, you would not be able to place any security related code or data in the files, such as a mysql username or password or email account information, any security exploits present in the code could be found and used, and things like database table and column names would be exposed which would make sql injection easier.

 

Not to mention that every include using this method on a web page will generate a separate http request to the web server where the files are located, then that web server must serve up the file requested and send it back to the requesting web server, thereby slowing down the loading of the main web page., by a varying amount of time for each include.

 

I suppose you could have the contents encrypted and then decrypt them on the receiving server, but this would increase the size of the data transferred, which would make the loading of the page even slower, and then the decryption would add even more processing time.

 

Short answer - For the include() method (assuming you can work out all the security problems) the small amount of your time you would save by being able to update files on one common site, will be wasted many times over because each time a page is displayed that is including that code, will be slower.

 

You could also write a php script that uses FTP functions to write the files from the common server to each site that needs the files or use FTP to read the files from the common server to each site that needs the files. But, don't try to include() the files remotely.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.