forked from StartBootstrap/startbootstrap-sb-admin-2
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvalidate_input.php
67 lines (59 loc) · 1.4 KB
/
validate_input.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
if (isset($_POST)){
//PRINT OROGINAL $_POST
/*
echo 'qua ci arrivo <br>';
foreach ($_POST as $key => $value) {
echo '<p>'.$key.'</p>';
echo '<p>'.$value.'</p>';
$value = trim($value);
$value = stripslashes($value);
$value = htmlspecialchars($value);
foreach($value as $k => $v){
echo '<p>'.$k.'</p>';
echo '<p>'.$v.'</p>';
$v = trim($v);
$v = stripslashes($v);
$v = htmlspecialchars($v);
echo '<hr />';
}
}
echo "<br>";
*/
// qua valido i $_POST
$_POST = array_map_deep($_POST, trim);
$_POST = array_map_deep($_POST, stripslashes);
$_POST = array_map_deep($_POST, htmlspecialchars);
function array_map_deep( $value, $callback )
{
if ( is_array( $value ) ) {
foreach ( $value as $index => $item ) {
$value[ $index ] = array_map_deep( $item, $callback );
}
} elseif ( is_object( $value ) ) {
$object_vars = get_object_vars( $value );
foreach ( $object_vars as $property_name => $property_value ) {
$value->$property_name = array_map_deep( $property_value, $callback );
}
} else {
$value = call_user_func( $callback, $value );
}
return $value;
}
//PRINT NEW $_POST
/*
echo '<hr> anche qua ci arrivo <br>';
foreach ($_POST as $key => $value) {
echo '<p>'.$key.'</p>';
echo '<p>'.$value.'</p>';
foreach($value as $k => $v)
{
echo '<p>'.$k.'</p>';
echo '<p>'.$v.'</p>';
echo '<hr />';
}
}
*/
//exit;
}
?>