note 51390 added to function.stripslashes
| From: | john at NOSPAMdoe dot com | Date: | Tue, 29 Mar 2005 16:01:24 +0000 |
| Subject: | note 51390 added to function.stripslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87147@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.stripslashes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51390
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51390&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51390&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51390&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51390&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51390&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51390&report=yes
Search -- http://master.php.net/manage/user-notes.php