<?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>最优良人 &#187; 魔法函数</title>
	<atom:link href="http://www.zui88.com/view-tag/%e9%ad%94%e6%b3%95%e5%87%bd%e6%95%b0/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zui88.com/blog</link>
	<description>中山php&#124;最优网络</description>
	<lastBuildDate>Mon, 13 May 2013 04:56:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>php过滤敏感字符的一些相关函数--魔法函数应用</title>
		<link>http://www.zui88.com/blog/view-23.html</link>
		<comments>http://www.zui88.com/blog/view-23.html#comments</comments>
		<pubDate>Sat, 06 Aug 2011 18:01:50 +0000</pubDate>
		<dc:creator>lin</dc:creator>
				<category><![CDATA[后端程序]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[魔法函数]]></category>

		<guid isPermaLink="false">http://www.zui88.com/blog/?p=23</guid>
		<description><![CDATA[一，首先，先来看一下php.ini的两个配置参数 magic_quotes_gpc "1" PHP_INI_PERDIR PHP_INI_ALL in PHP]]></description>
			<content:encoded><![CDATA[<p>一，首先，先来看一下php.ini的两个配置参数</p>
<p>magic_quotes_gpc "1" PHP_INI_PERDIR PHP_INI_ALL in PHP <= 4.2.3. Removed in PHP 6.0.0. </p>
<p>作用范围是：ＷＥＢ客户服务端；<br />
作用时间：请求开始是，例如当脚本运行时</p>
<p>magic_quotes_runtime "0" PHP_INI_ALL Removed in PHP 6.0.0. </p>
<p>作用范围是：影响从文件中读取的数据或从数据库查询得到的数据。</p>
<p>以下是一些常用到的方法:</p>
<p>get_magic_quotes_gpc(void)</p>
<p>本函数取得 PHP 环境配置的变量 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。 </p>
<p>　　返回 0 表示关闭本功能； </p>
<p>　　返回 1 表示本功能打开。 </p>
<p>　　当 magic_quotes_gpc 打开时，所有的 ' (单引号), " (双引号), \ (反斜线) and 空字符会自动转为含有反斜线的溢出字符。</p>
<p>应用：</p>
<p>由于该参数不支持在php文件进行设置，如果通过本函数取得的变量magic_quotes_gpc 的值为false，我们可以<br />
利用addslashes()人工使用反斜线引用字符串</p>
<p>$var = get_magic_quotes_gpc()?$var:addslashes($var);</p>
<p>相反，如果通过本函数取得的变量magic_quotes_gpc 的值为true，我们希望字符串不被转义，那么可以利用stripslashes()去除自动添加的反斜杠 </p>
<p>get_magic_quotes_runtime()</p>
<p>一般情况下，应当将其关闭，否则从数据库读取出来的数据单引号、双引号和反斜杠都会被加上\，导致显示不正常。像Discuz，PHPWind都在公共文件的头部加上一句 </p>
<p>set_magic_quotes_runtime(0)</p>
<p>// Check if magic_quotes_runtime is active<br />
if(get_magic_quotes_runtime())<br />
{<br />
    // Deactive<br />
    set_magic_quotes_runtime(false);<br />
}</p>
<p>二、对于magic_quotes_runtime，我们统一关闭它，即set_magic_quotes_runtime(0)；不让从数据库读取出来的数据的单引号、双引号和反斜杠都自动被加上\。这样，对数据库的操作如下：添加数据到数据库之前，我们手动对数据进行addslashes(),而从数据库取出数据时，则作相反操作，即stripslashes()。</p>
<p>三、对于要序列化的内容，要保持裸数据，即要去掉转义，stripslashes(),然后在把序列化过的内容保存到数据库当中（注意，序列化过的内容是不带单引号（'）、双引号（"）、反斜线（\）的），示例如下：</p>
<p>$feedarr['body_data'] = serialize(stripslashes($body_data));</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zui88.com/blog/view-23.html/feed</wfw:commentRss>
		<slash:comments>345</slash:comments>
		</item>
	</channel>
</rss>
