-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdump_variables.php
More file actions
54 lines (40 loc) · 1.29 KB
/
dump_variables.php
File metadata and controls
54 lines (40 loc) · 1.29 KB
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
<?php
session_start();
// these lines format the output as HTML comments
// and call dump_array repeatedly
echo "<br> <br> BEGIN VARIABLE DUMP ";
echo "<br> <br> ======= BEGIN GET VARS =======";
echo "<br> <br> ======= ".dump_array($_GET)." =======";
echo "<br> <br> ======= BEGIN POST VARS =======";
echo "<br> <br> ======= ".dump_array($_POST)." =======";
echo "<br> <br> ======= BEGIN SESSION VARS =======";
echo "<br> <br> ======= ".dump_array($_SESSION)." =======";
echo "<br> <br> ======= BEGIN COOKIE VARS =======";
echo "<br> <br> ======= ".dump_array($_COOKIE)." =======";
echo "<br> <br> ======= END VARIABLE DUMP =======";
// dump_array() takes one array as a parameter
// It iterates through that array, creating a single
// line string to represent the array as a set
function dump_array($array) {
if(is_array($array)) {
$size = count($array);
$string = "";
if($size) {
$count = 0;
$string .= "{ ";
// add each element's key and value to the string
foreach($array as $var => $value) {
$string .= $var." = ".$value;
if($count++ < ($size-1)) {
$string .= ", ";
}
}
$string .= " }";
}
return $string;
} else {
// if it is not an array, just return it
return $array;
}
}
?>