Source of: /manual/en/security.magicquotes.disabling.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/security.magicquotes.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'security.magicquotes.disabling.php',
1 => 'Disabling Magic Quotes',
),
'up' =>
array (
0 => 'security.magicquotes.php',
1 => 'Magic Quotes',
),
'prev' =>
array (
0 => 'security.magicquotes.whynot.php',
1 => 'Why not to use Magic Quotes',
),
'next' =>
array (
0 => 'security.hiding.php',
1 => 'Hiding PHP',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="security.magicquotes.disabling" class="sect1">
<h2 class="title">Disabling Magic Quotes</h2>
<div class="warning"><b class="warning">Warning</b><p class="simpara">This feature has been
<em class="emphasis">DEPRECATED</em> as of PHP 5.3.0 and <em class="emphasis">REMOVED</em> as of PHP 6.0.0.
Relying on this feature is highly discouraged.</p></div>
<p class="para">
The <a href="info.configuration.php#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a>
directive may only be disabled at the system level, and not at
runtime. In otherwords, use of <a href="function.ini-set.php" class="function">ini_set()</a> is not
an option.
</p>
<p class="para">
</p><div class="example">
<p><b>Example #1 Disabling magic quotes server side</b></p>
<div class="example-contents para"><p>
An example that sets the value of these directives to
<i>Off</i> in <var class="filename">php.ini</var>. For additional details, read the
manual section titled <a href="configuration.changes.php" class="link">How to
change configuration settings</a>.
</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
; Magic quotes
;
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off
; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off
</pre></div>
</div>
<div class="example-contents para"><p>
If access to the server configuration is unavailable, use of
<var class="filename">.htaccess</var> is also an option. For example:
</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
php_flag magic_quotes_gpc Off
</pre></div>
</div>
</div><p>
</p>
<p class="para">
In the interest of writing portable code (code that works in any
environment), like if setting at the server level is not possible,
here's an example to disable <a href="info.configuration.php#ini.magic-quotes-gpc" class="link">
magic_quotes_gpc</a> at runtime. This method is inefficient so
it's preferred to instead set the appropriate directives elsewhere.
</p>
<p class="para">
</p><div class="example">
<p><b>Example #2 Disabling magic quotes at runtime</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">get_magic_quotes_gpc</span><span style="color: #007700">()) {<br /> </span><span style="color: #0000BB">$process </span><span style="color: #007700">= array(&</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">, &</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">, &</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">, &</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">);<br /> while (list(</span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$val</span><span style="color: #007700">) = </span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$process</span><span style="color: #007700">)) {<br /> foreach (</span><span style="color: #0000BB">$val </span><span style="color: #007700">as </span><span style="color: #0000BB">$k </span><span style="color: #007700">=> </span><span style="color: #0000BB">$v</span><span style="color: #007700">) {<br /> unset(</span><span style="color: #0000BB">$process</span><span style="color: #007700">[</span><span style="color: #0000BB">$key</span><span style="color: #007700">][</span><span style="color: #0000BB">$k</span><span style="color: #007700">]);<br /> if (</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$v</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$process</span><span style="color: #007700">[</span><span style="color: #0000BB">$key</span><span style="color: #007700">][</span><span style="color: #0000BB">stripslashes</span><span style="color: #007700">(</span><span style="color: #0000BB">$k</span><span style="color: #007700">)] = </span><span style="color: #0000BB">$v</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$process</span><span style="color: #007700">[] = &</span><span style="color: #0000BB">$process</span><span style="color: #007700">[</span><span style="color: #0000BB">$key</span><span style="color: #007700">][</span><span style="color: #0000BB">stripslashes</span><span style="color: #007700">(</span><span style="color: #0000BB">$k</span><span style="color: #007700">)];<br /> } else {<br /> </span><span style="color: #0000BB">$process</span><span style="color: #007700">[</span><span style="color: #0000BB">$key</span><span style="color: #007700">][</span><span style="color: #0000BB">stripslashes</span><span style="color: #007700">(</span><span style="color: #0000BB">$k</span><span style="color: #007700">)] = </span><span style="color: #0000BB">stripslashes</span><span style="color: #007700">(</span><span style="color: #0000BB">$v</span><span style="color: #007700">);<br /> }<br /> }<br /> }<br /> unset(</span><span style="color: #0000BB">$process</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div><?php manual_footer(); ?>