Jump to content

[SOLVED] include php file from remote domain


enkay

Recommended Posts

I have a main website and many "satellite" websites. I have a php file that I update very often on the main website and I want to include that file on all my other domains. Updating the file on each domain would require way too much time and be too much of a hassle.

 

I know some of you will say this is not a good idea because of security reasons but unless I figure out a better way to update hundreds of sites at once, it will have to do.

 

I have allow_url_include = 1.

 

The problem is that using the php include function makes the script run on the remote machine and only outputs the "result" onto the domain the user is accessing. Any variable or function declared in the included php file will be unsusable in the rest of the code.

 

Simple exemple of what I'm trying to do.

 

Content of: mainwebsite.com/include.php

<?
$something = "yes";
?>

 

Content of: remotewebsite.com/index.php

<?
include("http://mainwebsite.com/include.php");
echo $something;
?>

 

Desired output when accessing remotewebsite.com/index.php

the word "yes" written on the screen.

 

 

 

 

I'm open to any suggestion to make this work but please don't suggest something that would imply completely re-writing the way the website works.

 

Can it be done using some kind of ftp include? Is there anyway to make the domain on which the include file is stored appear as "local" to all my remote domains and therefore include would work as if the files were stored locally?

 

Thanks for you time and suggestions.

Link to comment
Share on other sites

Hm, I'm not the pro here but you could always set up a database that you could always connect to from anywhere. Inside this database would be a table and inside the table you could have a field that held your source code to the webpage your trying to show in different places.

 

This would allow you to just have a couple lines of db code to output the webpages source.

 

Then you could write a script( or manually) to input the source into the db.

 

 

Something along those lines might be easier? Although im sure theres a way to do some kind of ftp thingy.

Link to comment
Share on other sites

Thank you for your replies.

 

#1

If i was to get the php code of the file to be included in a string on the "satellite" website. Either by putting it in a text file or a database as you suggested, how would I then get it excuted?

 

Let's say I have this:

 

$code = "<? $something='yes' ?>";

 

How do I get that string executed as php content?

 

#2

If it can't be done with an include, is there any other function that could do it?

 

You say it could be done with ftp but it would be too slow, I'd like to try but how would it be done?

Link to comment
Share on other sites

Can it be done using some kind of ftp include? Is there anyway to make the domain on which the include file is stored appear as "local" to all my remote domains and therefore include would work as if the files were stored locally?

 

You could use nfs to share filesystems between systems, but again, this is very slow.

 

I think your best option would be to write a script on the main server that pushes any updates you make to this include file over to the remote systems. Simple to do if you have shell access on all the machines.

 

As an example.

 

#!/bin/bash

for server in foo.com boo.com bar.com ; do
  scp /var/www/site/include/file.php "${server}":/var/www/site/include/
done

Link to comment
Share on other sites

Argh.

 

The worst part is that those files are actually "local" and on the same server.

 

remotewebsite.com/index.php is really mainwebsite.com/remote1/index.php

 

The file to be include is mainwebsite.com/include.php.

 

 

Anyway I can go back to the root folder and use

include("../include.php");

 

While still appearing to be on remotewebsite.com ?

Link to comment
Share on other sites

Argh.

 

The worst part is that those files are actually "local" and on the same server.

 

remotewebsite.com/index.php is really mainwebsite.com/remote1/index.php

 

The file to be include is mainwebsite.com/include.php.

 

 

Anyway I can go back to the root folder and use

include("../include.php");

 

While still appearing to be on remotewebsite.com ?

 

In that case, just use the full path to the file in question.

Link to comment
Share on other sites

I think your best option would be to write a script on the main server that pushes any updates you make to this include file over to the remote systems. Simple to do if you have shell access on all the machines.

 

As an example.

 

#!/bin/bash

for server in foo.com boo.com bar.com ; do
  scp /var/www/site/include/file.php "${server}":/var/www/site/include/
done

 

This seems like an interesting suggestion but I have no clue how to implant it. I'm using godaddy for my hosting. They're usually "looser" than some other hosting companies as they let me set any setting I want in my php.ini and .htacess files.

 

Maybe they would let me do this too?

 

What should I research to better understand how to make this work? I currently have no clue how to do any of that.

Link to comment
Share on other sites

In that case, just use the full path to the file in question.

 

Unfortunately using the full path, it just processes the php and doesn't let me use any functions or variables declared in the included file.

 

I also cant seem to use a relative path with ../ because that would require to go up higher than what is supposed to be the root folder of remotewebsite.com

 

On the main website I use relative paths for my includes and everything works fine.

 

The problem is trying to use some of those files in my remote websites. Which all have their own URL but are located in their own sub folder of my main website.

Link to comment
Share on other sites

Unfortunately using the full path, it just processes the php and doesn't let me use any functions or variables declared in the included file.

 

Do you have http:// at the start of this path? If so, that is not a path but a url. try using the path to the file.

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.