mysql escape 注入_在哪里使用mysql_real_escape_string防止SQL注入?

bd96500e110b49cbb3cd949968f18be7.png

I'm in trouble with a group of hackers. they hacked my client's site few times, and my client gets more angry :( my client lost his database (which has hundreds records), and had to enter all :(

now I'm following some more introductions;

fixed file permissions

changed ftp and host login info

cleared all remote mysql accesses

now working on SQL Injection issue. I added mysql_real_escape_string to admin panel login paramaters. So where else should I use this mysql_real_escape_string ? I have few email forms at site, I dont think i need to add there...

I have an index.php as a mainpage. Should I do anything for this page to prevent any sql injection attack via url like index.php?somesql= ?

Please advise me! I appreciate so much!!! :(

for example:

I have such code;

public function showDetails($id) {

// SQL Jobs Details

$this->sql_job = "SELECT * FROM jobs WHERE id=".mysql_real_escape_string($id);

$this->rst_job = mysql_query($this->sql_job);

$this->row_all = mysql_fetch_assoc($this->rst_job);

// SQL State

$this->sql_state = "SELECT title FROM state WHERE id=" . $this->row_all[$this->tbl_jobs['f4']];

$this->rst_state = mysql_query($this->sql_state);

$this->row_state = mysql_fetch_assoc($this->rst_state);

........

is it enough to use mysql_real_escape_string for $id . not for $this->row_all[$this->tbl_jobs['f4']]

解决方案

Basically, each time you use some unsafe data (user input, value from a database, a file or an external website, i.e. any data that you are not 100% sure that it is safe) in a SQL query, you should escape it using mysql_real_escape_string. Note that according to OWASP, this function is not secure for escaping dynamic table names (but this is far less common than "basic" user input insertion).

I suggest you to have a look at the whole OWASP article on SQL injection, and also to browse the rest of the website. It's a great source of information about security in web applications.

IMO, the preferred way of preventing SQL injection is to use prepared statements.

Please remember that if you do choose to use mysql_real_escape_string() it only works when

used inside a string that is delimited by quotes. Never use it on

any unquoted values. This includes numeric values; instead, validate that the user-input is actually numeric.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值