在WordPress中,将自定义字段数据插入文件而不是数据库

时间:2013-01-12 20:50:11

标签: php wordpress custom-fields

有没有办法将数据从WordPress自定义字段插入自定义文件而不是MySQL数据库?

我想这样做的原因是因为我试图为用户设置一个自定义字段作为一种PHP沙箱,我想在模板文件中使用include filename.php并避免插入PHP数据进入数据库以及随之而来的安全漏洞,或者更糟糕的是,必须在从数据库中检索数据后使用eval

我愿意接受任何其他建议来实现这一目标,但我认为最简单的方法是将数据存储在一个随机的php文件中并完全绕过数据库。

1 个答案:

答案 0 :(得分:1)

让我先说一下:

这是一个坏主意

您的想法是让最终用户上传您随后将在您的服务器上执行的PHP脚本。是什么阻止攻击者上传这样的脚本:

<?php
// get a list of all of the wp-config.php files available to this user
$configs = shell_exec("cd ~ && find `pwd` -name wp-config.php");
// go through every match and email the contents 
// of the file to my super secret hacker email or whatever
// btw i now have mysql credentials for all of your wp sites.
?>

这甚至都没有想象力。

这里说的是如何做到

在WP网站上下载并安装https://github.com/fyaconiello/WP_Bad_Idea作为插件

然后将其添加到主题的single-attack_post.php

<h3>THE CODE</h3>
<pre>
<?php include($post->attack_code); ?>
</pre>