我想知道是否有办法eval()从我的代码中删除。
在此函数中,我通过 POST 加载一些变量,以根据管理员在表单上插入的内容在我的数据库上更新或插入新用户。
public function alterUser()
{
$name = $_POST['name']; //required field
$contact = $_POST['contact']; //required field
$password = $_POST['password']; //required field
$string = "DB::table('users')";
if(isset($_POST['id'])){
$string = $string."-> where ('id', \$_POST['id']) ->update([";
}else{
$string = $string."-> insert([";
}
$string = $string."'name' => \$_POST['name'],";
if (isset($_POST['email']))
$string = $string."'email' => \$_POST['email'],";
$string = $string."'password' => Hash::make(\$password),'contacto' => \$contact,";
if (isset($_POST['nif']))
$string = "$string.'nif' => \$nif,";
$string = $string."]);";
eval($string);
return redirect('/user');
}
由于这会带来一些安全漏洞,还有其他替代方案可以使其发挥作用吗?
四季花海
BIG阳
慕少森