简体   繁体   English

网页不会解析PHP代码

[英]Webpage won't parse PHP code

I'm trying to add some of my own PHP to a nearly-unreadable template file on a forum system. 我正在尝试将一些自己的PHP添加到论坛系统上几乎无法读取的模板文件中。 I know it all works perfectly as far as the server config, etc. goes, but PHP simply doesn't parse on this page. 我知道,就服务器配置等而言,它完全可以正常工作,但PHP根本不解析此页面。 JS works fine. JS工作正常。 Any ideas? 有任何想法吗? It's a simple .html page. 这是一个简单的.html页面。

尝试将此添加到.htaccess(或在相应的目录中创建一个新的):

AddType application/x-httpd-php .php .html

Is it possible that the template file is being read into a variable rather than being included or required? 模板文件是否可能被读入变量而不是被包含或需要? Eg. 例如。 it's loaded using file_get_contents or something similar? 它是使用file_get_contents或类似的东西加载的?

If this is the case you may need to eval() the template code after it has been loaded as file_get_contents does not parse php code, it just loads the text as it is into a variable. 如果是这种情况,您可能需要在加载模板代码之后eval()因为file_get_contents不解析php代码,它只是将文本加载到变量中。 It's a very ugly solution but it may work for you. 这是一个非常难看的解决方案,但它可能对你有用。 Please be careful if you do this as it does open up a whole can of security issue worms. 如果你这样做,请小心,因为它确实打开了一整套安全问题蠕虫。

A lot of template systems use their own coding syntax. 许多模板系统使用自己的编码语法。 If this is the case it will not be possible to include PHP code in your template without opening up a lot of security holes. 如果是这种情况,则无法在不打开大量安全漏洞的情况下在模板中包含PHP代码。

Try to learn the specific templating language used, or find out where you should put the code without changing the template file (there may be a controller or plugin system built for such stuff). 尝试学习所使用的特定模板语言,或者在不更改模板文件的情况下找出应该放置代码的位置(可能有为这些内容构建的控制器或插件系统)。

您的页面必须是.php页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM