note 51390 deleted from function.stripslashes by philip
| From: | philip@php.net | Date: | Wed, 07 Feb 2007 04:56:26 +0000 |
| Subject: | note 51390 deleted from function.stripslashes by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123014@lists.php.net to get a copy of this message | ||
Note Submitter: john at NOSPAMdoe dot com
----
To avoid having to repeatedly check for magic quotes, use this piece of code:
<?php
eval('function cndstrips($str)
{
return ' . (get_magic_quotes_gpc() ? 'stripslashes($str)' : '$str') .
';
}');
?>
somewhere in the first lines. After this, you can use cndstrips (conditional strip slashes, ofcourse
you can rename) instead of stripslashes, and without having to worry about stripping normal strings.
Don't overdo it, however.
If stripping slashes just once is all that matters, try something like this:
<?php
if (get_magic_quotes_gpc())
{
if (is_array($_POST)
foreach($_POST as $k=>$v) if (is_string($v) $_POST[$k] = stripslashes($v);
if (is_array($_COOKIE)
foreach($_COOKIE as $k=>$v) if (is_string($v)$_COOKIE[$k]= stripslashes($v);
if (is_array($_GET)
foreach($_GET as $k=>$v) if (is_string($v) $_GET[$k] = stripslashes($v);
}
?>
This works with PHP4.