一款从不同域访问时看起来不同的 PHP 应用程序

发布于 2024-10-01 07:40:20 字数 311 浏览 2 评论 0原文

我在一家小型网页设计公司工作,我们希望实施一个自制的 CMS 来帮助管理我们的网站。

目前,我们将 CMS 安装在每个客户的唯一用户下的单独文件夹中,然后将他们的域指向该文件夹。

困难的部分是向后移植重要的更改,例如异步新的谷歌分析代码,或者我们改进的防止垃圾评论的方法。

关于更好的方法的几个问题:

1:是否建议为我们生成的每个站点使用相同的后端代码?

2:假设是,最好的方法是什么?我想检查 $_SERVER['SERVER_NAME'] 来确定使用哪个模板、数据库连接等。

任何人以前有这样做的经验吗?

I'm working for a small web design firm and we are looking to implement a home brewed CMS to help manage our sites.

Currently we install our CMS in a separate folder under a unique user for each customer, then point their domain at that folder.

The difficult part with this is backporting important changes, for instance that async new google analytics code, or our improved way of preventing comment spam.

A couple of questions about a better way:

1: is it advisable to use the same backend code for every site we produce?

2: Assuming yes, what's the best way? I'd though of checking $_SERVER['SERVER_NAME'] to determine which template, database connection etc to use.

Anyone any previous experience of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小霸王臭丫头 2024-10-08 07:40:20

如果它们都托管在同一台物理服务器上,您需要 $_SERVER['HTTP_HOST'],这是用户请求的域。 SERVER_NAME 是服务器本身的物理名称(由 Apache 的 ServerName 指令设置)。

如果多个站点彼此之间没有太大差异,那么在同一代码库上托管多个站点是没有问题的。如果这只是一些品牌和改变一些文本/图形的问题,那么没什么大不了的。但如果您正在做根本不同的网站,那么您的代码将变得难以维护,混乱不堪,“如果服务器名称是 X,则执行此操作,否则执行其他操作”。

If they're all hosted on the same physical server, you'd want $_SERVER['HTTP_HOST'], which is the domain the user is requesting. SERVER_NAME is the physical name of the server itself (which is set by Apache's ServerName directive).

There's no problem hosting multiple sites off the same code base, if they're not too different from each other. If it's just a matter of some branding and changing bit of text/graphcis here and there, no biggie. But if you're doing fundamentally different sites, then your code will become an unmaintainable mess of "if servername is X then do this else do something else".

蓬勃野心 2024-10-08 07:40:20

我已经尝试过这种方式,有一个主要的 CMS 推出了多个站点,并在它上线之前就放弃了它。我们遇到的问题是更新和更改。任何类型的定制都可以直接完成,无需大量额外工作。想要添加表单字段吗?准备好迎接心痛吧。最后,我们做了您现在所做的事情,多次安装,但使用了一些主要脚本,它们都共享,其中调用脚本通过了哪个站点请求什么,例如表单邮件程序和安全检查。

对于我们知道所有文件或多个页面都相同的批量更新,我们要么编写一个在文件中搜索和替换的更新脚本,要么在 BBedit 中执行。

对于像谷歌分析这样的东西,我有一种感觉,无论如何你都将被迫手动进行这些更改,因为它们都有唯一的 ID。

I've tried it that way, having one main CMS that pushed out multiple sites, and moved away from it before it went live. The problems we had were with updates and changes. Any kind of customization is right out the window without a lot of extra work. Want to add a form field? Get ready for heartache. In the end we did what you have now, multiple installs, but with a few major scripts the they all shared in which the calling scripts passed which site was requesting what, such as the form mailer and security checks.

For mass updates that we knew would be the same across all of them, or across multiple pages we'd either write an update script that'd search and replace in the files, or do it in BBedit.

With something like google analytics I have a feeling you'd be forced to make those changes manually anyway since they would all have unique ID's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文