Skip to content

Commit d866034

Browse files
authored
Update Input.php
1 parent 020f532 commit d866034

File tree

1 file changed

+106
-5
lines changed

1 file changed

+106
-5
lines changed

Input.php

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,126 @@
11
<?php
22

3+
namespace App;
4+
35
class Input {
6+
/**
7+
* Must take @bool to proceed
8+
* refer to getMagicQuotes() method
9+
*
10+
* @var boolean
11+
*/
12+
private static $magic_quotes_exists;
13+
14+
415
public static function exists($action = 'post') {
516
switch ($action) {
617
case 'post':
718
return (!empty($_POST)) ? true : false;
819
break;
20+
921
case 'get':
1022
return (!empty($_GET)) ? true : false;
1123
break;
24+
1225
default:
1326
return false;
1427
}
28+
1529
}
1630

17-
public static function get($name) {
31+
32+
public static function get($name, $purify = false) {
33+
1834
if (isset($_POST[$name])) {
19-
return $_POST[$name];
35+
$var = $_POST[$name];
36+
37+
return self::verify($var, $purify);
2038
}else if (isset($_GET[$name])) {
21-
return $_GET[$name];
39+
$var = $_GET[$name];
40+
41+
return self::verify($var, $purify);
42+
}
43+
44+
return false;
45+
}
46+
47+
48+
public static function verify($input, $purify = false) {
49+
$input = is_array($input) ? array_map('self::verify', $input) : static::sanitize($input, $purify);
50+
51+
return $input;
52+
}
53+
54+
public static function check($name, $in = '') {
55+
$in = strtolower($in);
56+
57+
switch ($in) {
58+
case 'get':
59+
if (isset($_GET[$name])) {
60+
return true;
61+
}
62+
break;
63+
64+
case 'post':
65+
if (isset($_POST[$name])) {
66+
return true;
67+
}
68+
break;
69+
70+
default:
71+
if (isset($_POST[$name])) {
72+
return true;
73+
}else if (isset($_GET[$name])) {
74+
return true;
75+
}
2276
}
23-
return '';
77+
78+
return false;
79+
}
80+
81+
82+
public function sanitize($string, $purify = false)
83+
{
84+
$string = trim($string);
85+
86+
if ($purify==true)
87+
$string = stripslashes(strip_tags($string));
88+
89+
$string = htmlentities($string, ENT_QUOTES, "UTF-8");
90+
91+
return $string;
2492
}
25-
}
93+
94+
public function getMagicQuotes() {
95+
if(function_exists('get_magic_quotes_gpc')) {
96+
self::$magic_quotes_exists = true;
97+
return self::$magic_quotes_exists;
98+
}
99+
}
100+
101+
/**
102+
* Convert post request into url param string
103+
*
104+
* @param array $stream
105+
* @param string $initParam
106+
* @return string $params
107+
*/
108+
public function splitStream($stream, $initParam = '') {
109+
$params = !empty($initParam) ? $initParam : '';
110+
$magicQuotesExist = self::getMagicQuotes();
111+
112+
foreach ($stream as $key => $value) {
113+
if ($magicQuotesExist == true && get_magic_quotes_gpc() == 1) {
114+
$value = urlencode(stripslashes($value));
115+
}else {
116+
$value = urlencode($value);
117+
}
118+
119+
$params .= !empty($params) ? '&' : '';
120+
$params .= "$key=$value";
121+
}
122+
123+
return $params;
124+
}
125+
126+
}

0 commit comments

Comments
 (0)