Simulate asp response PHP code in php
/** Author: Xuehu blog * class purpose: implement 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 se TOutput ($ output, $ 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 ;}}