Including Files Between Sites

I have a file at mysite/2B/dbc.php that I would like to include in a page on another website, mysite2. Can someone show me the right way to do it?

After perusing http://ro1.php.net/manual/en/function.include.php I tried this:

include $_SERVER['DOCUMENT_ROOT']."/2B/dbc.php";

But that didn’t work. I understand you can do it with OOP, but I haven’t figured it out yet.

I posted the code I’ve been using below. It’s worked fine for years until today. I asked my webhost to enable PDO, and everything blew up. First, they told me there was a conflict between PDO and my .htaccess files - and he was apparently right, because commenting out a certain line restored my sites. However, my inter-site includes are no longer working; I get a “permission denied” error.

Even more bizarre, a tech support guy told me that you can’t include files between two CPanel accounts - even though that’'s exactly what I’ve been doing forever!

Anyway, I asked them to disable PDO, which will hopefully restore my sites. In the meantime, I’d like to figure out a new way to include files before I have PDO re-enabled. Thanks.


switch (PHP_OS)
{
 case 'Linux':
 $BaseINC = '/home/jinxguy2/public_html';
 $BaseURL = 'http://www.jinx.org';
 break;

 case 'Darwin':
 break;

 default:
 break;
}

include ($BaseINC."/2B/dbc.php");

P.S. Is it true that you can’t include files between two CPanel accounts? I mean it obviously isn’t technically true, because I’ve been doing it. But does CPanel somehow impede with the process?

I just tried including your site index.html and got the following errors:


Warning: include() [function.include]: 
http:// wrapper is disabled in the server configuration by allow_url_include=0 in 
  /home/MYSITE/www/index-include-TEST.php on line 28

Warning: include(http://www.jinx.org/index.html) [function.include]:
  failed to open stream: no suitable wrapper could be found in 
   /home/MySite/www/index-include-TEST.php on line 28

Warning: include() [function.include]: Failed opening 'http://www.jinx.org/index.html' for inclusion 
 (include_path='.:/www/ZZZ/XXX:/YYY/local/lib/php') in 
 /MySite/www/index-include-TEST.php on line 28  

I tried using PHP file_get_contents(…); and it worked fine:



error_reporting(-1);
ini_set('display_errors', true);

$remoteFile = 'http://www.jinx.org/index.html';
$contents = file_get_contents($remoteFile); 
echo $contents;

Thanks, but I don’t think that will work in this case, because I’m not just echoing static text. I guess my database query is pretty simple, but the other key include in turn includes a variety of files with complex scripts, database queries, etc. If I’m not mistaken, dynamic code can’t be included with file_get_contents, right? I’ll give it a try, though…

Yes, I just tried it, and it works great at including content - but not dynamic code. Thanks, though.

P.S. I just talked to another support tech who told me CPanel has been upgraded to disallow sharing files between sites. I guess it was a huge vulnerability; lots of malicious use. That means I’m going to have to go back to square one develop each site independently.

I am amazed that “disallow sharing files between sites.” was allowed.

The configuration directory from your Main Site could be copied to your Other Sites and as far as I know the database is common across your Main Site and all Other Sites. Databases available on all my sites with no problem.

Ya, I’m grabbing DB content across sites as well on the SAME server. Not grabbing files though.

Yes, I verified that I can make remote database connections.

Thanks for reminding me about file_get_contents, which you told me about recently. I used it to get custom 404 error pages up on all my sites really quickly; I just made a master 404 page on my main site and used file_get_contents to pipe it into the other sites.

This is unreal. My peak traffic begins in just a few days, and I took this entire week off from work to work on my websites, only to have them blow up in my face. Anyway, I’ll probably set a new world record reconfiguring my sites. :wink:

Someone suggested that I could still include files between sites if I switched to a VPS. So I asked some questions about that here.