사이트 내 전체검색
PHP
[php] 간단한 디버그 함수
로빈아빠
https://cmd.kr/php/547 URL이 복사되었습니다.

본문

간단한 디버그 함수

코딩을 하다보면 POST나 GET 이런 변수들을 찍어 보는 경우가 있습니다.
이럴때 사용하면 좋을 것 같습니다.

$debug = 1;
function DebugPrint($bugType) {
		// ECHO DebugPrint('_SERVER _GET _POST _COOKIE _FILES _SESSION _ENV');
		global $debug;
		if($debug != 1) return;
		
		$var_array = array();
		$debug_html = '<table border="0" width="80%" cellpadding="0" cellspacing="1" bgcolor="#0099FF" align="center">';
		// _SERVER
		if(count($_SERVER) > 0 && eregi('_SERVER',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_SERVER</td></tr>'; 
				$var_array = $_SERVER;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}
		// _GET
		if(count($_GET) > 0 && eregi('_GET',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_GET</td></tr>'; 
				$var_array = $_GET;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}
		// _POST
		if(count($_POST) > 0 && eregi('_POST',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_POST</td></tr>'; 
				$var_array = $_POST;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}
		// _COOKIE
		if(count($_COOKIE) > 0 && eregi('_COOKIE',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_COOKIE</td></tr>'; 
				$var_array = $_COOKIE;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}
		// _FILES
		if(count($_FILES) > 0 && eregi('_FILES',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_FILES</td></tr>'; 
				$var_array = $_FILES;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}
		// _SESSION
		if(count($_SESSION) > 0 && eregi('_SESSION',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_SESSION</td></tr>'; 
				$var_array = $_SESSION;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}
		// _ENV
		if(count($_ENV) > 0 && eregi('_ENV',$bugType)) {
				$debug_html .= '<tr class="padding5 bold center"><td colspan=2 style="color:#FFFFFF">$_ENV</td></tr>'; 
				$var_array = $_ENV;
				foreach($var_array as $key => $value)  
						$debug_html .= '<tr class="padding5" bgcolor="#FFFFFF"><td class="bold">'.$key.'</td><td>'.$value.'</td></tr>'; 
				unset($var_array);
		}


		$debug_html .= '</table>';

		return $debug_html;
}

댓글목록

등록된 댓글이 없습니다.

PHP
871 (9/18P)

Search

Copyright © Cmd 명령어 18.221.167.11