For people having trouble with magic quotes


#1

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.


#2

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

  • Dallas
  • DreamHost Head Honcho/Founder

#3

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


Simon Jessey
Keystone Websites | si-blog


#4

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:

[code]= 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 [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 array inputs as well as string inputs.
[/code]


#5

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


Simon Jessey
Keystone Websites | si-blog


#6

Thanks :slight_smile:

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.