【发布时间】:2011-03-18 14:17:21
【问题描述】:
我有一个带有选项页面的 wordpress 主题。我已经包含了一个基本的导出/导入选项功能。导出功能允许用户将选项下载到文本 .dat 文件并将它们存储在自己的计算机上。导入选项按钮读取 .dat 文件并覆盖数据库中的当前选项。然后在脚本执行结束时删除该文件(不存储在服务器中)。
没有单独的 uploads.php 文件,一切都发生在一个脚本中(导出、导入等)。
我尝试导入一些 php 文件和其他类型的文件,唯一发生的事情是选项被清除了。但这就是应该发生的事情,导入的文件应该替换数据库中的任何内容。
用户只有在以管理员权限登录 WordPress 仪表板时才能访问此表单。
所以没有必要在这个导入表单上设置广泛的安全功能,是吗?除了,也许我应该用 .sql 文件试试,看看会发生什么?有人可能会创建一个 .sql 文件并清除整个数据库吗?为了安全起见,我应该将 .sql 文件列入黑名单吗?
这是我的导入代码:
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'export' == $_POST['action']) {
cpress_export();
}
if (isset($_FILES['settings'])){
if ($_FILES["settings"]["error"] > 0){
echo "Error: " . $_FILES["settings"]["error"] . "<br />";
} else{
$rawdata = file_get_contents($_FILES["settings"]["tmp_name"]);
$cp_options = unserialize($rawdata);
update_option('cpress_options', $cp_options);
header("Location: themes.php?page=options_page.php&import=true");
}
}
这是我的导出代码(在同一个文件中):
function cpress_export(){
$settings = get_option('cpress_options');
$file_out = serialize($settings);
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-type: text/plain; charset=ISO-8859-1");
header('Content-Disposition: attachment; filename="cpress-options-'.date("Ymd").'.dat"');
echo $file_out;
exit;}
【问题讨论】:
-
为什么在 cpress_export() 的末尾回显 $file_out?
-
这是一个导出 - 您必须在标头之后将数据发送给客户端!
标签: php security wordpress import export