没有参数绑定的PHP SQL注入预防 [英] PHP SQL injection prevention without parameter binding

查看:52
本文介绍了没有参数绑定的PHP SQL注入预防的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何在 PHP 中防止 SQL 注入?

我正在为我的大学图书馆的视频流媒体网站工作.我正在使用 PHP 和 MySql.我没有在这个项目中使用任何参数化查询.

I am working for a video streaming website for my college library. I am using PHP and MySql. I have not used any parameterized queries in this project.

最近我开始了解 SQL 注入.现在我的代码快完成了,我必须在接下来的两天内提交项目,我现在如何确保我的代码没有 SQL 注入倾向?

Recently I came to know about SQL injections. Now that my code is almost done and I have to submit the project in the next two days, how can I now ensure that my code is not SQL injection prone?

将整个内容转换为参数化接口是我现在无法做到的.我现在应该怎么做才能避免在我的网站上发生 SQL 注入?

Converting the whole thing in to a parameterized interface is what I can't do now. What should I do now to avoid SQL Injections on my website?

推荐答案

防止 SQL 注入的基本思想(如果不使用 Prepared Statements)转义数据.

The basic idea to prevent SQL injections (if not using Prepared Statements) is to escape your data.

当您将一些预期的整数值注入 SQL 查询时,请确保它是一个整数,使用 intval().

When you inject some expected integer value into an SQL query, make sure it's an integer, using intval().

当您的表格中有小数/数字字段时,请使用 floatval().

When you have a decimal/numeric field in your table, use floatval().

当你的表中有一个字符串 (char, varchar, text) 字段时,使用你的 API 提供的函数来转义字符串:

And when you have a string (char, varchar, text) field in your table, use the function provided by your API to escape strings :

这篇关于没有参数绑定的PHP SQL注入预防的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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