English 中文(简体)
澄清我sqli_real_efall_string:储存在数据库中
原标题:clarification on mysqli_real_escape_string: storing in database

为了赢得避免卡片注射攻击,I m 期待着清理我的网站用户输入的所有文本(和大多数其他数据),然后将其输入储存数据库。

I was under the impression that the function inserted backslashes ( ) before all characters capable of being malicious ( , , " , etc ), and expected that the returned string would contain the newly added backslashes.

我对载有这种潜在恶性特征的编织物进行了简单测试,并对该文件作了回应,确切地看到了我所期望的一点:用斜坡来扼杀这些特性。

因此,我着手在数据中添加清理功能,然后储存到数据库中。 我在为数据储存而建造的询问中加入(Msqli_real_einski_string(链接,显示美元)。 我很惊讶地测试了该书,我(对我方略)注意到,数据库中储存的数据似乎并未包含斜坡。 我测试、测试和测试,但都没有结果,一米损失。

Any suggestions? Am I missing something? I was expecting to then have to remove the backslashes with the stripslashes($string) function, but there doesn t seem to be anything to strip...

最佳回答

当你在数据库中看到成功插入的数据时,如果用<密码>mysql_real_einski_string(),请在上不要查询数据库中的斜坡。 这是因为在Kall问询表中只需要 escaping击。 mysql_real_einski_string(> sanitizes it for内插入(或更新,或其他查询投入),但在数据储存时确实导致数据的长期修改。

In general, you do not want to store modified or sanitized data in your database, but instead should be storing the data in its original version. For example, it is best practice to store complete HTML strings, rather than to store HTML that has been encoded with PHP s htmlspecialchars().

When you retrieve it back out from the database, there is no need for stripslashes() or other similar unescaping. There are some legacy (mis-)features of PHP like magic_quotes_gpc that had been designed to protect programmers from themselves by automatically adding backslashes to quoted strings, requiring `stripslashes() to be used on output, but those features have been deprecated and now mostly removed.

问题回答

MySQL stores the data without the slashes (although it is passed to the RDBMS with the slashes). So you don t need to use stripslashes() later on.

你们可以肯定,由于其他原因,扼杀会失败。

I m 设法清理我的网站用户输入的所有文本(和大多数其他数据)

这就是你正在做的错误。

  1. mysqli_real_escape_string does not "cleanse" anything. There is no word "cleanse" in it s name.
  2. You should format, not "cleanse" your data. And different data require different formatting.
  3. You should format ALL the data, not only data entered by the user of my website

以目前的形式,你将网站置于非常易受攻击和错误的境地。

I was under the impression that the function inserted backslashes ( ) before all characters capable of being malicious ( , , " , etc ),

To let you know, there is nothing malicious in any character. There are some service characters, that can be misinterpreted in some circumstances.
But adding backslashes doesn t make your data automatically "safe". Some injections doesn t require any special characters. So, you need to properly format your data, not just use a some sort of magic that will make you magically safe





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签