Skip to content
Snippets Groups Projects
functions.php 37.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • </body>
    </html>
    <?php
    
    	// If a database connection was established (before this error) we close it
    	if ($db_error)
    		$GLOBALS['db']->close();
    
    	exit;
    }
    
    // DEBUG FUNCTIONS BELOW
    
    //
    // Display executed queries (if enabled)
    //
    function display_saved_queries()
    {
    	global $db, $lang_common;
    
    	// Get the queries so that we can print them out
    	$saved_queries = $db->get_saved_queries();
    
    ?>
    
    <div id="debug" class="blocktable">
    	<h2><span><?php echo $lang_common['Debug table'] ?></span></h2>
    	<div class="box">
    		<div class="inbox">
    			<table cellspacing="0">
    			<thead>
    				<tr>
    					<th class="tcl" scope="col">Time (s)</th>
    					<th class="tcr" scope="col">Query</th>
    				</tr>
    			</thead>
    			<tbody>
    <?php
    
    	$query_time_total = 0.0;
    	while (list(, $cur_query) = @each($saved_queries))
    	{
    		$query_time_total += $cur_query[1];
    
    ?>
    				<tr>
    					<td class="tcl"><?php echo ($cur_query[1] != 0) ? $cur_query[1] : '&nbsp;' ?></td>
    					<td class="tcr"><?php echo pun_htmlspecialchars($cur_query[0]) ?></td>
    				</tr>
    <?php
    
    	}
    
    ?>
    				<tr>
    					<td class="tcl" colspan="2">Total query time: <?php echo $query_time_total ?> s</td>
    				</tr>
    			</tbody>
    			</table>
    		</div>
    	</div>
    </div>
    <?php
    
    }
    
    
    //
    // Unset any variables instantiated as a result of register_globals being enabled
    //
    function unregister_globals()
    {
    	$register_globals = @ini_get('register_globals');
    	if ($register_globals === "" || $register_globals === "0" || strtolower($register_globals) === "off")
    		return;
    
    	// Prevent script.php?GLOBALS[foo]=bar
    	if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']))
    		exit('I\'ll have a steak sandwich and... a steak sandwich.');
    	
    	// Variables that shouldn't be unset
    	$no_unset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
    
    	// Remove elements in $GLOBALS that are present in any of the superglobals
    	$input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
    	foreach ($input as $k => $v)
    	{
    		if (!in_array($k, $no_unset) && isset($GLOBALS[$k]))
    		{
    			unset($GLOBALS[$k]);
    			unset($GLOBALS[$k]);	// Double unset to circumvent the zend_hash_del_key_or_index hole in PHP <4.4.3 and <5.1.4
    		}
    	}
    }
    
    
    //
    // Dump contents of variable(s)
    //
    function dump()
    {
    	echo '<pre>';
    
    	$num_args = func_num_args();
    
    	for ($i = 0; $i < $num_args; ++$i)
    	{
    		print_r(func_get_arg($i));
    		echo "\n\n";
    	}
    
    	echo '</pre>';
    	exit;
    }