PHP simulates the Response class implementation method in ASP, Aspresponse
In this paper, we describe the method of PHP simulating response class in ASP. Share to everyone for your reference. Specific as follows:
Used to ASP or ASP, they will often use the response class, this class is used to handle the client's response, can achieve jump, output and other functions. There is no such class in PHP, but it is true that the class can be modeled by a function.
/* Class Purpose: Implements Response function similar to ASP */final class Response {Private $headers = array (); Private $output; Private $level = 0; Public Function AddHeader ($key, $value) {$this->headers[$key] = $value; Public Function Removeheader ($key) {if (Isset ($this->headers[$key])) {unset ($this->headers[$key]); }} Public Function redirect ($url) {header (' location: '. $url); Exit The Public Function setoutput ($output, $level = 0) {$this->output = $output; $this->level = $level; } Private Function Compress ($data, $level = 0) {if (Isset ($_server[' http_accept_encoding ')) && (Strpos ($_se rver[' http_accept_encoding '], ' gzip ')!== FALSE) {$encoding = ' gzip '; } if (Isset ($_server[' http_accept_encoding ') && (Strpos ($_server[' http_accept_encoding '], ' x-gzip ')!== fals E) {$encoding = ' x-gzip '; } if (!isset ($encoding)) {return $data; } if (!extension_loaded (' zlib ') | | inI_get (' zlib.output_compression ')) {return $data; } if (Headers_sent ()) {return $data; } if (Connection_status ()) {return $data; } $this->addheader (' content-encoding ', $encoding); Return Gzencode ($data, (int) $level); Public function output () {if ($this->level) {$ouput = $this->compress ($this->output, $this->le VEL); } else {$ouput = $this->output; } if (!headers_sent ()) {foreach ($this->headers as $key = + $value) {header ($key. ': ' . $value); }} echo $ouput; } }
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1044857.html www.bkjia.com true http://www.bkjia.com/PHPjc/1044857.html techarticle PHP simulates the implementation method of response class in ASP, Aspresponse the method of response class in PHP simulating ASP in this case. Share to everyone for your reference. The specific following: used to ASP or a ...