如何防止Laravel中的SQL注入? [英] How to prevent SQL injection in Laravel?
本文介绍了如何防止Laravel中的SQL注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的控制器中,我有以下代码:
In my controller I have this code:
public function create($brand_id)
{
Brand::findOrFail($brand_id);
}
和这个:
public function search()
{
$q = Input::get('q');
$brands = Brand::where('title', 'LIKE', '%'.$q.'%')->take(80)->get();
此代码安全吗? 安全"是指SQL注入安全.还是应该在这里进行一些变量清理?清理用户输入的最佳方法是什么? 非常感谢您的帮助:)
Is this code safe? By "safe" I mean SQL injection safe. Or should I do some variable clean up here? And what is the best way for cleaning up user input? Thanks a lot for helping me :)
推荐答案
是,Eloquent在后台使用参数绑定,可以安全地转义where()中使用的任何输入.
yes Eloquent uses parameter binding behind the scene, which safely escapes any input used in where().
这篇关于如何防止Laravel中的SQL注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文