Source for file MagicQuotesUtil.php

Documentation is available at MagicQuotesUtil.php


1 <?php
2 // MagicQuotesUtil: A Utility Class for Handling Magic Quotes
3 // Copyright (C) 2003 Lukas Feiler
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 /**This file contains the class MagicQuotesUtil.
20 *
21 * @package MagicQuotesUtil
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**A Utility Class for handling MagicQuotes.
28 *
29 * This class provides just one public method: undo. Calling this method will undo all magic quoting performed by
30 * the PHP Engine. Using this class allows you to write code that works with every setup - magic quotes enabled
31 * or not. Usage:
32 * <code>
33 * require_once('MagicQuotesUtil/MagicQuotesUtil.php');
34 * MagicQuotesUtil::undo();
35 * </code>
36 * Please note that global variables will stay untouched!
37 *
38 * @author Lukas Feiler <lukas.feiler@chello.at>
39 * @version 0.1.9
40 * @copyright Lukas Feiler 2003
41 * @package MagicQuotesUtil
42 * @static
43 */
44 class MagicQuotesUtil {
45
46 /**Undoes all magic quoting performed by the PHP Engine.
47 *
48 * This method removes the magic quotes from $HTTP_GET_VARS,
49 * $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $_REQUEST, $_GET, $_POST
50 * and $_COOKIE. Please note that global variables will stay untouched!
51 * You can call this method only once. Calling it a second time will
52 * have no effect.
53 * @access public
54 */
55 function undo()
56 {
57 global $HTTP_GET_VARS $HTTP_POST_VARS $HTTP_COOKIE_VARS
58 static $called;
59
60 if ($called) {
61 return;
62 }
63 MagicQuotesUtil::_removeFromArray($_REQUEST);
64 MagicQuotesUtil::_removeFromArray($_GET);
65 MagicQuotesUtil::_removeFromArray($_POST);
66 MagicQuotesUtil::_removeFromArray($_COOKIE);
67 MagicQuotesUtil::_removeFromArray($HTTP_GET_VARS);
68 MagicQuotesUtil::_removeFromArray($HTTP_POST_VARS);
69 MagicQuotesUtil::_removeFromArray($HTTP_COOKIE_VARS);
70 $called = true;
71 }
72
73 /**Removes all magic quotes from the array passed by reference.
74 * @access private
75 */
76 function _removeFromArray(&$array)
77 {
78 if (is_array($array)) {
79 while (list($key, $val) = each($array)) {
80 if (is_array($array[$key])) {
81 continue;
82 }
83 if (ini_get('magic_quotes_sybase') && get_magic_quotes_gpc()) {
84 $array[$key] = str_replace("''","'",$array[$key]);
85 } elseif (get_magic_quotes_gpc()) {
86 $array[$key] = stripslashes($array[$key]);
87 }
88 }
89 }
90 }
91 }
92 ?>

Documentation generated on Mon, 8 Dec 2003 13:10:36 +0100 by phpDocumentor 1.2.3