通过 CMS 管理网站配置

发布于 2024-11-03 11:00:29 字数 899 浏览 1 评论 0原文

我在 Stack Overflow 上读过与此问题非常相似的问题,但并不完全相同。

假设我的网站的每个页面上都包含以下 config.inc.php 文件:

<?php

    $site_name = 'Acme Inc.';

    $authenticate_with_ldap = true;

    $ldap_host = 'ldap.example.com';
    $ldap_port = 389;
    $ldap_rdn = 'ldap-user';
    $ldap_password = 'ldap-pass';
    $ldap_dn = 'ou=example,dc=example,dc=com';

    $smtp_username = 'smtp-user';
    $smtp_password = 'smtp-pass';

    $recaptcha_publickey = 'my-recaptcha-publickey';
    $recaptcha_privatekey = 'my-recaptcha-privatekey';

?>

注意:我选择将网站配置保存在文件中而不是数据库中,因为该信息在整个网站上使用,并且它会需要更多的代码,而且我猜,必须始终在数据库中查询相同的信息会产生更多的开销。

现在假设网站管理员是那种更喜欢使用 CMS 编辑上述信息而不是手动编辑文件的人。我担心的是,当网站管理员单击“更新”按钮并且 PHP 脚本到达覆盖 config.inc.php 文件的 file_put_contents 函数时,可能会出现问题并损坏文件或由于语法错误或其他原因使其无法使用。

这是一个合理的担忧吗?我应该告诉网站管理员他应该坚持下去并手动编辑文件吗?我应该将信息存储在数据库中吗?或者我应该将信息存储在两个地方,以便如果文件弄乱,可以使用数据库中的信息重新生成它?

I've read questions on Stack Overflow very similar to this question, but not quite the same.

Let's say that I had the following config.inc.php file included on every page of my website:

<?php

    $site_name = 'Acme Inc.';

    $authenticate_with_ldap = true;

    $ldap_host = 'ldap.example.com';
    $ldap_port = 389;
    $ldap_rdn = 'ldap-user';
    $ldap_password = 'ldap-pass';
    $ldap_dn = 'ou=example,dc=example,dc=com';

    $smtp_username = 'smtp-user';
    $smtp_password = 'smtp-pass';

    $recaptcha_publickey = 'my-recaptcha-publickey';
    $recaptcha_privatekey = 'my-recaptcha-privatekey';

?>

Note: I have chosen to keep the website configuration in a file instead of the database because the information is used all over the website and it would be a lot more code and, I'm guessing, a lot more overhead to have to query the database for the same information all the time.

Now let's say that the website administrator is the type of person who would prefer to edit the above information using a CMS as opposed to going in and editing the file manually. My fear is that when the website administrator clicks the "Update" button and the PHP script gets to the file_put_contents function that overwrites the config.inc.php file, something could go wrong and either corrupt the file or make it unusable due to a syntax error or something.

Is this a reasonable concern? Should I tell the website administrator that he should just tough it out and edit the file manually? Should I store the information in the database instead? Or should I store the information in both places so that if the file gets messed up, it can be regenerated using the information in the database?

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

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

发布评论

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

评论(1

蹲墙角沉默 2024-11-10 11:00:29

如果您将该信息作为单行数据存储在数据库中,它不会被缓存吗?

If you store that info in the DB as a single row of data, wouldn't it be cached anyway?

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