PHP 作为模板引擎存储在 Mysql 中 - 白名单函数 [英] PHP as template engine stored in Mysql - Whitelist Functions

查看:33
本文介绍了PHP 作为模板引擎存储在 Mysql 中 - 白名单函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我已经阅读了无数关于使用 PHP 作为模板引擎(使用输出缓冲)的帖子,但我仍在努力为它辩护.

While I have been reading through countless posts about using PHP as a template engine (using output buffering), I'm still trying to make a case for it.

因为我想知道是否可以将 PHP 用作网络应用程序的模板引擎(用户将能够自己更改布局)--我仍然没有找到有关以下内容的任何信息:

As I'm wondering if I could use PHP as a template engine for a web app (users will be able to change the layout themselves) -- I still don't find any info regarding the following:

  • 将模板存储在 MYSQL 数据库中
  • 评估他们
  • 但只包括列入白名单的函数(让他们只能访问有限的一组函数——while、foreach 等......)

有人正在寻找相同的解决方案,但可以提供更多信息吗?那会很不错.

Anybody looking for the same solution, but can chime in with a bit more information? That would be quite nice.

推荐答案

如果您不能信任编辑模板的用户,最好使用单独的模板语言.

If you can't trust the user editing the template, you are better off using a separate templating language.

请注意,Smarty 等许多模板语言也提供代码执行功能.您可能需要禁用引擎配置中的那些.

Note that many template languages like Smarty provide code execution functions as well. You may need to disable those in the engine's configuration.

在 PHP 中禁用所有潜在危险的功能是一项非常艰巨的任务,而且很容易搞砸.请参阅可利用的 PHP 函数

Disabling all potentially dangerous functions in PHP is a very arduous task, and easy to screw up. See Exploitable PHP functions

这篇关于PHP 作为模板引擎存储在 Mysql 中 - 白名单函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆