<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>addslashes &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/addslashes/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 08:14:05 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>addslashes,mysql_real_escape_string</title>
		<link>https://www.mudbest.com/addslashesmysql_real_escape_stringmysql_escape_string/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Thu, 15 Mar 2012 01:56:20 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[addslashes]]></category>
		<category><![CDATA[escape_string]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=950</guid>

					<description><![CDATA[可能还是有些PHP开发人员使用addslashes进行防止SQL注入，在这里还是建议加强中文防止SQL注入的检 ... <a title="addslashes,mysql_real_escape_string" class="read-more" href="https://www.mudbest.com/addslashesmysql_real_escape_stringmysql_escape_string/" aria-label="阅读 addslashes,mysql_real_escape_string">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>可能还是有些PHP开发人员使用addslashes进行防止SQL注入，在这里还是建议加强中文防止SQL注入的检查，addslashes的问题在于黑客可以用0xbf27来代替单引号，而addslashes只是将0xbf27修改为0xbf5c27，成为一个有效的多字节字符，其中的0xbf5c仍会被看作是单引号，所以addslashes无法成功拦截。</p>
<p>当然addslashes也不是毫无用处，它是用于单字节字符串的处理，多字节字符还是用mysql_real_escape_string吧。</p>
<p>对于php手册中get_magic_quotes_gpc的举例：<span id="more-950"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
if (!get_magic_quotes_gpc()) {
	$lastname = addslashes($_POST&#x5B;'make']);
	} else {
	$lastname = $_POST&#x5B;'make'];
}
?&gt;
</pre>
<p>最好对magic_quotes_gpc已经开放的情况下，还是对$_POST[’make’]进行检查一下。</p>
<p>再说下mysql_real_escape_string和mysql_escape_string这2个函数的区别：<br />
mysql_real_escape_string 必须在(PHP 4 >= 4.3.0 PHP 5)的情况下才能使用。否则只能用 mysql_escape_string .<br />
两者的区别是：<br />
mysql_real_escape_string 考虑到连接的当前字符集，而mysql_escape_string 不考虑。</p>
<p>总结一下：</p>
<p><strong>addslashes()</strong> 是强行加；</p>
<p><strong>mysql_real_escape_string()</strong> 会判断字符集，但是对PHP版本有要求；</p>
<p><strong>mysql_escape_string</strong>不考虑连接的当前字符集。</p>
<p><strong>mysql_real_escape_string()</strong>函数用于转义SQL语句中的特殊字符，该函数的语法格式如下：</p>
<p>    string <strong>mysql_real_escape_string</strong> ( string $unescaped_string<br />
    [, resource $link_identifier ] ) </p>
<p>在上述语法中涉及到的参数说明如下。</p>
<p>unescaped_string：未转义的字符串。</p>
<p>link_identifier：MySQL的连接标识符。</p>
<p><strong>mysql_real_escape_string()</strong>函数不转义&#8221;%&#8221; 和 &#8220;_&#8221;这两个符号。</p>
<p>使用函数<strong>mysql_real_escape_string()</strong>函数的示例代码如下：</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$connection=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;root&quot;)
or die(&quot;连接服务器失败&quot;);
$person= &quot;Jone's and Bobo's teacher&quot;;
$escaped_person= mysql_real_escape_string($person);
echo $escaped_person;
?&gt; 
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
