简体   繁体   中英

Including Files Between Websites

I have several websites that function like one big CMS, with all sites based on includes hosted by one central website. I posted code from one of the satellite sites below to illustrate how I include files.

The problem is that I just activated PDO online, and it's causing all kinds of problems. There's apparently a conflict between PDO and my .htaccess files that I'm working on. At the same time, my includes aren't being included.

So I'd like to ask if there's an alternate method of including files between websites online, at least until I can fix the PDO/Apache problem(s). Thanks.

$path = $_SERVER['REQUEST_URI'];
$path2 = str_replace('/', '', $path);

$Section  = current(explode('/', ltrim($path, '/'), 2));  // Main line 
$Sections = array('Introduction', 'Topics', 'World', 'Ecosymbols', 'Glossary', 'Reference',  'Links', 'About', 'Search');

if ( ! in_array($Section, $Sections)) 
{ 
 // die('Invalid section: ' . $Section); 
} 

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

 case 'Darwin':
 // Just some code for my local includes...
 break;

 default:
 break;
}

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

Note: Here are the error messages I'm getting from the home page of one affected site. ACE.php is the name of the file that contains the code I posted above.

Warning: include(/home/geobear2/public_html/2B/dbc.php) [function.include]: failed to open stream: Permission denied in /home/symbolos/public_html/1A/ACE.php on line 67

Warning: include() [function.include]: Failed opening '/home/geobear2/public_html/2B/dbc.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/symbolos/public_html/1A/ACE.php on line 67

Warning: include(/home/geobear2/public_html/2B/inc/A1.php) [function.include]: failed to open stream: Permission denied in /home/symbolos/public_html/index.php on line 31

Warning: include() [function.include]: Failed opening '/home/geobear2/public_html/2B/inc/A1.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/symbolos/public_html/index.php on line 31

I believe you're asking the wrong question... the way you "include" files in your application is a bit wrong and, i might say, "oldschool".

You should not include from other websites... if they are hosted on the same server you can use (if you have enough access, some servers will forbid you to do this), absolute paths for includes.

Also, your method will slow you down, and i doubt it worked in the first place...

See how include works here: http://ro1.php.net/manual/en/function.include.php +++ cross reference require, require_once, include_once.

Elegant solution: If you read the documentations properly and play around with it, granted your server has a newer version of php (5.3 atleast from what i remember, i may be wrong), you can start using namespaces.

Docs: http://www.php.net/manual/en/language.namespaces.php

This is a wonderful way to have a common set of classes to use within your apps. OOP knowledge is a must, for that i can't guide you much, there are hundreds of wonderful tutorials online.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM