intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Secure PHP Development- P24

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:5

59
lượt xem
4
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Secure PHP Development- P24: Welcome to Secure PHP Development: Building 50 Practical Applications. PHP has come a long way since its first incarnation as a Perl script. Now PHP is a powerful Web scripting language with object-oriented programming support. Slowly but steadily it has entered the non-Web scripting arena often reserved for Perl and other shell scripting languages. Arguably, PHP is one of the most popular Web platforms.

Chủ đề:
Lưu

Nội dung Text: Secure PHP Development- P24

  1. 86 Part II: Developing Intranet Solutions Listing 4-3 (Continued) } function print_banner() { if ($this->banner_printed == TRUE) { return 0; } $out = “myTextColor’>” . “Debugger started for $this->prefix” . “”; if ($this->buffer == TRUE ){ $this->buffer_str .= $out; } else { echo $out; $this->banner_printed = TRUE; } return 1; } function write($msg) { $out = sprintf(“%03d  ” . “%s\n”, $this->myTextColor, $this->line++, $this->color, $msg); if ($this->buffer == TRUE) { $this->buffer_str .= $out; } else { echo $out; } }
  2. Chapter 4: Architecture of an Intranet Application 87 function debug_array($hash = null) { while(list($k, $v) = each($hash)) { $this->write(“$k = $v”); } } function set_buffer() { $this->buffer = TRUE; } function reset_buffer() { $this->buffer = FALSE; $this->buffer_str = null; } function flush_buffer() { $this->buffer = FALSE; $this->print_banner(); echo $this->buffer_str; } } ?> The debugger class has the following methods: ◆ Debugger(): This is the constructor function for the debugger class (class.Debugger.php). This function initializes the color, prefix, line, and buffer_str, banner_printed member variables. The color is used to display the debug information in a given color. The prefix variable is used to prefix each debug message displayed, which allows for easier identifi- cation of messages. The line variable is initialized to zero, which is automatically incremented to help locate debug information quickly. The buffer_str variable is used to store buffered debug information. The banner_printed variable, which
  3. 88 Part II: Developing Intranet Solutions controls the banner printing, is set to FALSE. The debugger can be invoked in an application called test_debugger1.php as follows: In this example, a new Debugger object called $myDebugger is created, which will print debug messages in red color and use ‘MAIN’ as the prefix for each message. The buffering of debug messages is disabled as well. ◆ print_banner(): This function prints a banner message as follows: Debugger started for PREFIX The PREFIX is set when the object is created.
  4. Chapter 4: Architecture of an Intranet Application 89 ◆ write(): This function displays a debug message using the chosen color and automatically prints the debug message line number. If debug buffer- ing is on, then the message is written to the buffer (buffer_str). ◆ debug_array(): This function allows you to debug an associative array. It prints the contents of the associative array parameter using the write() method. ◆ set_buffer(): This function sets the buffering of debug messages. ◆ reset_buffer(): This function resets the buffering of debug messages. ◆ flush_buffer(): This function prints the buffer content along with the debug banner. Now let’s look at how an application called test_debugger2.php can use this debugging facility:
  5. 90 Part II: Developing Intranet Solutions // Write the variable out using debugger write() method $myDebugger->write(“Name = $name”); ?> This will print a message such as the following: 000   Name = M. J. Kabir Buffering debug messages enables you to print all debug messages together, which is often very beneficial in identifying a flow sequence. For example, here an application called test_debugger3.php buffers debugging information and prints the information when the buffer is flushed using flush_buffer() method found in the Debugger class.
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
9=>0