安全用户提供阵列字符串转换成PHP数组? [英] Safely convert user-provided array string into PHP array?

查看:100
本文介绍了安全用户提供阵列字符串转换成PHP数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户需要能够进入的参数的PHP数组。

Users need to be able to enter a PHP array of parameters.

目前,他们看到,他们有望进入PHP code,它定义了一个数组文本区:

Currently, they see a text area where they are expected to enter PHP code that defines an array:

<textarea name="foo">
$bar = array( 'key' => 'value' );
</textarea>

我得到的文本面积的值,例如,字符串$ _GET ['富'。

I get the value of the text area as, for instance, the string $_GET['foo'].

我怎么可以解析,这样我可以使用数组$吧?我宁愿不使用eval,如果我能帮助它。

How can I parse this so that I can use the array $bar? I'd rather not use eval if I can help it.

谢谢!

推荐答案

如果你绝对必须有用户定义这样的数组,你将是让他们把它定义为JSON好得多。这很容易转换和你没有LEX它像PHP的code;比EVAL更安全。此外,JSON是定义数组一个轻量级的和简单的方法,所以这将是对他们一个更好的用户体验,以及:)

If you absolutely must have the user define the array in this manner, you will be much better off by letting them define it as json. It's easy to convert and you dont have to lex it like the php code; much safer than eval. Plus, json is a lightweight and easy way to define arrays, so it will be a nicer user experience for them as well :)

这篇关于安全用户提供阵列字符串转换成PHP数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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