PHP simulates the response class implementation method in asp, aspresponse. PHP simulates the response class implementation method in asp. aspresponse this article describes how PHP simulates the response class in asp. Share it with you for your reference. Specifically: get used to asp or a PHP to simulate the response class implementation method in asp, aspresponse
This example describes how to simulate the response class in PHP asp. Share it with you for your reference. The details are as follows:
People who are used to asp or asp.net development often use the response class, which is used to process client responses and implement jump and output functions. this class does not exist in php, but it can be simulated using functions.
/** Usage: implements the 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;} public function setOutput ($ out Put, $ level = 0) {$ this-> output = $ output; $ this-> level = $ level;} private function compress ($ data, $ level = 0) {if (isset ($ _ SERVER ['http _ ACCEPT_ENCODING ']) & (strpos ($ _ SERVER ['http _ ACCEPT_ENCODING'], 'gzip ')! = FALSE) {$ encoding = 'gzip ';} if (isset ($ _ SERVER ['http _ ACCEPT_ENCODING']) & (strpos ($ _ SERVER ['http _ ACCEPT_ENCODING '], 'X-gzip ')! = FALSE) {$ 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-> level );} else {$ ouput = $ this-> output;} if (! Headers_sent () {foreach ($ this-> headers as $ key => $ value) {header ($ key. ':'. $ value) ;}} echo $ ouput ;}}
I hope this article will help you with php programming.
Examples in this article describes how PHP simulates the response class in asp. Share it with you for your reference. The specifics are as follows: get used to asp or...