For people having trouble with magic quotes

For people having trouble with magic quotes

Posted by: pureform
Posted on: 2005-10-05 15:34:00

If you have PHP running as CGI, you cannot turn magic quotes off ... not through .htaccess, and neither through ini_set() [at least it didn't work for me]. So I whipped up this script which filters everything for you:

	# This filters all incoming data
foreach($_REQUEST as $key => $value) {
if (is_array($_REQUEST[$key])) {
$_REQUEST[$key] = array_map("stripslashes",$_REQUEST[$key]);
} else {
$_REQUEST[$key] = stripslashes($_REQUEST[$key]);
}
$$key = $_REQUEST[$key];
}


It's safe for array inputs as well as string inputs.

Re: For people having trouble with magic quotes

Posted by: dallas
Posted on: 2005-10-06 16:46:00

This is great for the wiki if you feel inclined to add it there.

- Dallas
- DreamHost Head Honcho/Founder

Re: For people having trouble with magic quotes

Posted by: scjessey
Posted on: 2005-10-07 07:38:00

Presumably, that is just for PHP4. PHP5 is supposed to have them switched off by default.

Re: For people having trouble with magic quotes

Posted by: pureform
Posted on: 2005-10-07 22:33:00

I'm having a whole lot of trouble adding a NEW page to the wiki ...... I just can't figure it out. I created the wiki markup for it though, if you would like to post it for me:

= Magic Quotes in PHP =

'''NOTE:''' PHP5 has Magic Quotes turned OFF by default.

If you have [[PHP]] running as CGI, you '''cannot''' turn Magic Quotes OFF ... not through [[.htaccess]], and neither through [http://www.php.net/ini_set ini_set()].

So I whipped up this script which filters everything for you:

<?php
foreach($_REQUEST as $key => $value) {
if (is_array($_REQUEST[$key])) {
$_REQUEST[$key] = array_map("stripslashes",$_REQUEST[$key]);
} else {
$_REQUEST[$key] = stripslashes($_REQUEST[$key]);
}
$$key = $_REQUEST[$key];
}
?>

It's safe for <tt>array</tt> inputs as well as <tt>string</tt> inputs.


Re: For people having trouble with magic quotes

Posted by: scjessey
Posted on: 2005-10-08 06:26:00

In reply to:

I'm having a whole lot of trouble adding a NEW page to the wiki


I've added the page for you: http://wiki.dreamhost.com/index.php/PHP_Magic_Quotes

Re: For people having trouble with magic quotes

Posted by: pureform
Posted on: 2005-10-08 12:33:00

Thanks :-)

I'm sure in time I'll find out how to use wikis, but even the help files weren't all that helpful [as to how to ADD a page to the wiki].

Thanks again.

Tags: magicquotesforeachhtaccessinicgirunningphp