enkay Posted November 18, 2008 Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/ Share on other sites More sharing options...
snowman15 Posted November 18, 2008 Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692457 Share on other sites More sharing options...
DarkWater Posted November 18, 2008 Share Posted November 18, 2008 You can't include files from other servers directly. FTP functions would be way too slow for this sort of application, but you can try it if you want. Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692460 Share on other sites More sharing options...
enkay Posted November 18, 2008 Author Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692465 Share on other sites More sharing options...
DarkWater Posted November 18, 2008 Share Posted November 18, 2008 1) You could use eval(). It's slow too though. 2) Not really. I think you should really rethink your strategy. =P Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692468 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692472 Share on other sites More sharing options...
enkay Posted November 18, 2008 Author Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692475 Share on other sites More sharing options...
darkfreaks Posted November 18, 2008 Share Posted November 18, 2008 have you made sure the include function is not disabled in PHP you could always try require_once(),include_once() Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692476 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692481 Share on other sites More sharing options...
enkay Posted November 18, 2008 Author Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692483 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 Given that all your sites are on the same physical server there is simply no need to do what your attempting. Simply include the file as normal. Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692485 Share on other sites More sharing options...
enkay Posted November 18, 2008 Author Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692488 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 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 https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692490 Share on other sites More sharing options...
DarkWater Posted November 18, 2008 Share Posted November 18, 2008 Full path =/= URL Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692491 Share on other sites More sharing options...
enkay Posted November 18, 2008 Author Share Posted November 18, 2008 Oh.. Sorry. Still new at all this and self taught! I'm now googling what a full path is. Thank you! Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692494 Share on other sites More sharing options...
trq Posted November 18, 2008 Share Posted November 18, 2008 Everyone (most anyways) is self taught. There are relative paths and absolute (full) paths. Neither of which are uri's. Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692495 Share on other sites More sharing options...
enkay Posted November 18, 2008 Author Share Posted November 18, 2008 Thank you very much everyone, it worked! I'm glad the answer was that simple and I learned something new! I came close to throwing my computer out the window if I had to rewrite all that code in a different way! Link to comment https://forums.phpfreaks.com/topic/133142-solved-include-php-file-from-remote-domain/#findComment-692499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.