php-debug-console

Gesponsorde koppelingen

PHP script bestanden

  1. php-debug-console

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php

/**
 * A usefull debug class Please report bugs at kjarli@gmail.com
 * or at the website you downloaded this script from
 *
 * Ideas and suggestions always welcome!
 *
 * @link       http://www.phphulp.nl/php/scripts/4/1168
 * @author     iltar van der berg
 * @version    1.0.0
 *
 */

class debug_console
{
    /**
     * debug, if true, display errors and debug
     *
     * @var boolean
     */

    public $debug = false;

    /**
     * if true, overwrites the debug and shows ALL data
     *
     * @var boolean
     */

    public $debug_extra = false;

    /**
     * create an array of error messages to be returned
     *
     * @var array
     */

    public $error_messages = array();

    /**
     * the settings you want to load
     *
     * @var array
     */

    public $load_ini_settings = array();
    
    /**
     * create a new and unique file for the debug console result
     *
     * @var bool
     */

    public $debug_win_new_file = false;
    
    /**
     * define the debug window width
     *
     * @var string
     */

    public $debug_win_width = '750';
    
    /**
     * define the debug window height
     *
     * @var string
     */

    public $debug_win_height = '500';
    
    /**
     * define the debug window width
     *
     * @var string
     */

    public $debug_resizable = 'no';
    
    /**
     * if true, one or more errors are returned
     *
     * @var boolean
     */

    private $error = false;

    /**
     * noting for now...
     *
     */

    public function __construct()
    {
        
    }


    /**
     * manually print the array of the string
     * than choose wether to echo the array or return it in a string
     *
     * @param array $array
     * @param bool[optional] $echo_array
     * @return string
     */

    public function print_array($array, $echo_array = true)
    {

        if($echo_array)
        {

            echo '<pre>';
            print_r($array);
            echo '</pre>';
        }

        else
        {
            return '<pre>' . print_r($array, true) . '</pre>';
        }
    }


    /**
     * return the array stats, use the print_array function to display it
     *
     * @param array $array
     * @return array
     */

    public function array_stats($array)
    {

        // for each array, give the number of keys and values
        $array_stats[] = 'The array has ' . count($array) . ' values and keys.';

        foreach($array as $key => $value)
        {

            if($value == NULL)
            {

                // there is no value
                $array_stats[] = 'The array key [' . $key . '] is <strong>NULL</strong>';
            }

            elseif(is_array($value))
            {

                // it is an array, walk thatone too
                $array_stats[] = $this->array_stats($value);
            }

            else
            {
                // it has a value
                $array_stats[] = 'The array key [' . $key . '] is ' . $value;
            }
        }


        return $array_stats;
    }


    /**
     * upon destruction, return data to create the debug console
     *
     */

    public function __destruct()
    {

        // define the output string and create the html popup

        $output =
        '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Debug Console</title>
            <style>
            body
            {
                padding : 10px;
                margin  : 0px;
            }
            
            h1,
            h2,
            h3,
            h4
            {
                font-family : verdana;
            }
            div
            {
                width : 100%;
            }
                
            pre
            {
                font-size   : 12px;
            }
            
            fieldset
            {
                margin-top    : 10px;
                border        : 1px solid black;
                
                font-family   : verdana;
                color         : black;
                font-size     : 11px;
                padding       : 12px;
                margin-bottom : 10px;
            }
            legend
            {
                border-top    : 1px solid black;
                border-left   : 1px solid black;
                border-right  : 1px solid black;
                padding       : 3px 10px;
            }
            
        </style>
    </head>
    
    <body>
        '
;

        // get the user input to check
        $php_ini_check_user = $this->load_ini_settings;

        // these fields need to be checked by default
        $php_ini_check_auto = array
        (
            'asp_tags',
            'short_open_tag',
            'safe_mode',
            'max_execution_time',
            'max_input_time',
            'memory_limit',
            'display_errors',
            'log_errors',
            'register_globals',
            'register_long_arrays',
            'magic_quotes_gpc',
            'file_uploads',
            'upload_tmp_dir',
            'upload_max_filesize',
            'sql.safe_mode',
            'session_name',
            'session.gc_maxlifetime'
        );

        $php_ini_check_this = array_merge($php_ini_check_auto, $php_ini_check_user);

        $output .= '<h3>php.ini settings</h3>';

        // for each ini setting, check their value and make them readable for humans
        foreach($php_ini_check_this as $key => $value)
        {

            $ini_value = ini_get($value);

            if(empty($ini_value) || strtolower($ini_value) == 'off' || $ini_value == 0 || !$ini_value)
            {

                $ini_value = 'false';
            }

            elseif(strtolower($ini_value) == 'on' || $ini_value == 1)
            {

                $ini_value = 'true';
            }


            // create a box with the result
            $php_ini_settings[$value] =
            '
            <fieldset style="width: 200px; float:left;">
                <legend>'
. $value . '</legend>
                <strong>'
.$ini_value . '</strong>
            </fieldset>
            '
;
            $output .= $php_ini_settings[$value];
        }


        if($this->debug)
        {

            // normal debug is true, let's create a box
            $output .= '<div style="float:right">';
            $output .= '<h3>Debug returned</h3>';

            // check if the user has started a session
            if(isset($_SESSION))
            {

                // print the session array
                $output .= '<fieldset><legend>Sessions</legend>';
                $output .= $this->print_array($_SESSION, false);
                $output .= '</fieldset>';
            }


            // print the globals
            $output .= '<fieldset><legend>Globals</legend>';
            $output .= $this->print_array($GLOBALS, false);
            $output .= '</fieldset>';

            // print the cookies
            $output .= '<fieldset><legend>Cookies</legend>';
            $output .= $this->print_array($_COOKIE, false);
            $output .= '</fieldset>';

            // print the files
            $output .= '<fieldset><legend>Files</legend>';
            $output .= $this->print_array($_FILES, false);
            $output .= '</fieldset>';

            // print the get
            $output .= '<fieldset><legend>Get</legend>';
            $output .= $this->print_array($_GET, false);
            $output .= '</fieldset>';

            // print the post
            $output .= '<fieldset><legend>Post</legend>';
            $output .= $this->print_array($_POST, false);
            $output .= '</fieldset>';

            // print the request
            $output .= '<fieldset><legend>Request</legend>';
            $output .= $this->print_array($_REQUEST, false);
            $output .= '</fieldset>';

            $output .= '</div>';
        }

        elseif($this->debug_extra)
        {

            // the user wants a full data array, let's give it to him
            $output .= '<div style="float:right">';
            $output .= '<h3>Debug extra returned</h3>';

            // print the Declared classes
            $output .= '<fieldset><legend>Declared classes</legend>';
            $output .= $this->print_array(get_declared_classes(), false);
            $output .= '</fieldset>';

            // print the Declared_interfaces
            $output .= '<fieldset><legend>Declared interfaces</legend>';
            $output .= $this->print_array(get_declared_interfaces(), false);
            $output .= '</fieldset>';

            // print the Defined constants
            $output .= '<fieldset><legend>Defined constants</legend>';
            $output .= $this->print_array(get_defined_constants(), false);
            $output .= '</fieldset>';

            // print the Defined functions
            $output .= '<fieldset><legend>Defined functions</legend>';
            $output .= $this->print_array(get_defined_functions(), false);
            $output .= '</fieldset>';

            // print the Included files
            $output .= '<fieldset><legend>Included files</legend>';
            $output .= $this->print_array(get_included_files(), false);
            $output .= '</fieldset>';

            // print the Loaded extension
            $output .= '<fieldset><legend>Loaded extension</legend>';
            $output .= $this->print_array(get_loaded_extensions(), false);
            $output .= '</fieldset>';
            $output .= '</div>';
        }

        
        $output .=
        '
    </body>
</html>
        '
;
        
        $location = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
        $location = preg_replace('#/|\\\#', DIRECTORY_SEPARATOR,  $location);
        
        // check wether user wants a new file to save results, or overwrite the old file
        if(!$this->debug_win_new_file)
        {

            $file = 'default_result.php';
            $debug_file = $location .  $file;
        }

        else
        {
            $file = date('H^i^s-d^m^y') . '_result.php';
            $debug_file = $location . $file;
        }


        if(!file_put_contents($debug_file, $output))
        {

            die('The file <strong>' . $debug_file . '</strong> could not be created');
        }

        
        echo '
<script type="text/javascript">
<!--
    var WinOpt = "width='
. $this->debug_win_width . '";
    WinOpt += ", height='
. $this->debug_win_height . '";
    WinOpt += ", resizable='
. $this->debug_resizable . '";
    WinOpt += ", scrollbars=yes";
    WinOpt += ", toolbar=no";
    WinOpt += ", location=no";
    WinOpt += ", directories=no";
    WinOpt += ", status=no";
    WinOpt += ", menubar=no";
    WinOpt += ", copyhistory=no";
    WinOpt += ", top=50";
    WinOpt += ", left=50";

    var debugWin = open(\'./'
. $file . '\', \'DebugWindow\', WinOpt);
//-->
</script>
        '
;
    }
}


$debug = new debug_console();

//$debug->debug = true;
//$debug->debug_extra = true;
//$debug->debug_win_new_file = true;
//$debug->print_array($_SERVER, true);
//echo $debug->print_array($_SERVER, false);

//$debug->load_ini_settings = array('engine','zend.ze1_compatibility_mode','precision','y2k_compliance');

//$debug->print_array($debug->array_stats($array));


?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.