0

我的目标是拥有多个这样的网站:

www.mysite.com/site1/

www.mysite.com/site2/

www.mysite.com/site3/

www.mysite.com/site4/


这些站点的文件位于:

www.mysite.com/site_files/

这些包括网站的各种页面,以及 css、js 和图像。


这些页面中的每一个都将几乎相同,但将从不同的数据库加载内容,并且某些颜色以及某些图像会有所不同。

我只是好奇这样做的最佳方法是什么。我已经尝试index.php从网站中获取www.mysite.com/site_files/并包含它index.php

www.mysite.com/siteindex.php的内容:

<?php 

     $siteDB = "this";
     $domainName = "thisdomain";
     $twitterName = "thistwitter";
     $facebookName = "thisfacebook";

     include 'http://www.mysite.com/site_files/index.php'; 

?>

然后在 site_files index.php 中我会引用 $siteDB:

echo $siteDB;

使用此方法,变量不可用于包含的代码。

每个站点 index.php 都有不同的变量,但它们都包含相同的变量site_files/index.php

任何帮助,将不胜感激。

4

1 回答 1

3

这不起作用:

include 'http://www.mysite.com/site_files/index.php'; 

您需要访问与脚本相关的包含文件。或通过绝对网址:

include $_SERVER['DOCUMENT_ROOT'].'/site_files/index.php'; 

您的方法在技术上是可行的,但您应该在 Web 根目录下包含一个嵌套配置文件。

include $_SERVER['DOCUMENT_ROOT'].'/site1_config.php'; 
include $_SERVER['DOCUMENT_ROOT'].'/site_files/index.php';

配置定义数据库连接和任何其他站点特定详细信息的位置。

这是做到这一点的一种方法,可能是最接近您所拥有的方法。但不一定是“最好的”

在这种情况下,“最佳”是一个意见问题。

于 2012-11-07T01:19:45.713 回答