Smarty allowed_php_tag 报告“未定义的属性:Smarty::$allow_php_tag”

发布于 2024-11-30 15:30:36 字数 2125 浏览 3 评论 0原文

所以我有一个旧网站,它使用旧版本的 smarty,因为今天我想升级到最新版本,它给我带来了一个错误:

[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Notice:  Undefined property: Smarty::$allow_php_tag in /work/smarty3.1rc1/Smarty.class.php on line 592
[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/work/templates/modules/main_module.tpl"  on line 2 "{php}" unknown tag "php"' in /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php:596
Stack trace:
    #0 /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php(382): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ph...', 2)
    #1 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2383): Smarty_Internal_TemplateCompilerBase->compileTag('php', Array)
    #2 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2865): Smarty_Internal_Templateparser->yy_r38()
    #3 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2965): Smarty_Internal_Templateparser->yy_reduce(38)
    #4 in /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php on line 596

即使我安装了 Smarty 3.0.8,我也会遇到同样的错误... 由于网站中充满了 {php} 标签,因此无法删除该标签。 我能做些什么?

好的,按照 @Pekka 的说明,我发现了 Smarty Security 下一个问题:

$my_security_policy = new Smarty_Security($smarty);
$my_security_policy->allow_php_tag = true;
$my_security_policy->php_functions = array();
$my_security_policy->php_handling = Smarty::PHP_PASSTHRU;
$my_security_policy->php_modifier = array();
$my_security_policy->modifiers = array();

$smarty->enableSecurity($my_security_policy);

大喊:

[Fri Aug 19 12:06:40 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template .....' modifier 'strtolower' not allowed by security setting'

现在出了什么问题... $my_security_policy->php_functions = array(); 允许所有 php 函数..

So I have an old website which uses an older version of smarty, as today I wanted to upgrade to latest version, and it hit's me with an error:

[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Notice:  Undefined property: Smarty::$allow_php_tag in /work/smarty3.1rc1/Smarty.class.php on line 592
[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/work/templates/modules/main_module.tpl"  on line 2 "{php}" unknown tag "php"' in /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php:596
Stack trace:
    #0 /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php(382): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ph...', 2)
    #1 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2383): Smarty_Internal_TemplateCompilerBase->compileTag('php', Array)
    #2 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2865): Smarty_Internal_Templateparser->yy_r38()
    #3 /work/smarty3.1rc1/sysplugins/smarty_internal_templateparser.php(2965): Smarty_Internal_Templateparser->yy_reduce(38)
    #4 in /work/smarty3.1rc1/sysplugins/smarty_internal_templatecompilerbase.php on line 596

Even if I put Smarty 3.0.8 I get same errors ...
Since the website if full of {php} tags, removing is not an option.
What can I do?

Ok, as following @Pekka's instructions i found out about Smarty Security
Next problem:

$my_security_policy = new Smarty_Security($smarty);
$my_security_policy->allow_php_tag = true;
$my_security_policy->php_functions = array();
$my_security_policy->php_handling = Smarty::PHP_PASSTHRU;
$my_security_policy->php_modifier = array();
$my_security_policy->modifiers = array();

$smarty->enableSecurity($my_security_policy);

shouts:

[Fri Aug 19 12:06:40 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template .....' modifier 'strtolower' not allowed by security setting'

what's wrong now ... $my_security_policy->php_functions = array(); allows all php functions ..

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

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

发布评论

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

评论(1

难如初 2024-12-07 15:30:36

根据文档allow_php_tag现在Smarty_Security 类的属性,而不是 Smarty 的属性。请参阅该页面以获取如何使用它的示例。

我不知道什么时候发生了变化,但很可能是 V3 的新功能。这是一个很好的!

According to the docs, allow_php_tag is now a property of the Smarty_Security class, not Smarty. See the page for an example how to use it.

I don't know when this changed, but it's probable it's a new V3 feature. And a nice one at that!

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