input-magic-quotes
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
class Input {
public function __construct() {
$this->check_magic_quotes();
}
private function check_magic_quotes() {
if (get_magic_quotes_gpc()) {
$_GET = $this->fix_slashes($_GET);
$_POST = $this->fix_slashes($_POST);
$_SERVER = $this->fix_slashes($_SERVER);
}
}
private function fix_slashes($arr) {
if (is_array($arr)) {
foreach ($arr as $k => $v) {
$arr[$k] = is_array($v) ? $this->fix_slashes($v) : stripslashes($v);
}
return $arr;
}
else {
return stripslashes($arr);
}
}
public function get($key = '', $default = null) {
return isset($_GET[$key]) ? $_GET[$key] : $default;
}
public function post($key = '', $default = null) {
return isset($_POST[$key]) ? $_POST[$key] : $default;
}
public function cookie($key = '', $default = null) {
return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
}
public function server($key = '', $default = null) {
return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
}
}
?>
class Input {
public function __construct() {
$this->check_magic_quotes();
}
private function check_magic_quotes() {
if (get_magic_quotes_gpc()) {
$_GET = $this->fix_slashes($_GET);
$_POST = $this->fix_slashes($_POST);
$_SERVER = $this->fix_slashes($_SERVER);
}
}
private function fix_slashes($arr) {
if (is_array($arr)) {
foreach ($arr as $k => $v) {
$arr[$k] = is_array($v) ? $this->fix_slashes($v) : stripslashes($v);
}
return $arr;
}
else {
return stripslashes($arr);
}
}
public function get($key = '', $default = null) {
return isset($_GET[$key]) ? $_GET[$key] : $default;
}
public function post($key = '', $default = null) {
return isset($_POST[$key]) ? $_POST[$key] : $default;
}
public function cookie($key = '', $default = null) {
return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
}
public function server($key = '', $default = null) {
return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
}
}
?>