isSessionCookieCleanupNeeded() public static method

public static isSessionCookieCleanupNeeded ( ) : boolean
return boolean
Example #1
0
 /**
  * if this method is called in self::shutdown() it forces the browser to close the connection an allows the
  * shutdown-function to run in the background
  * @static
  * @return string
  */
 public static function outputBufferEnd($data)
 {
     $output = null;
     $contentEncoding = null;
     if (headers_sent()) {
         return $data;
     }
     // cleanup admin session Set-Cookie headers if needed
     // a detailed description why this is necessary can be found in the doc-block of \Pimcore\Tool\Session::$sessionCookieCleanupNeeded
     if (Tool\Session::isSessionCookieCleanupNeeded()) {
         $headers = headers_list();
         $headers = array_reverse($headers);
         foreach ($headers as $header) {
             if (strpos($header, Tool\Session::getOption("name")) !== false) {
                 header($header, true);
                 // setting the header again with 2nd arg = true, overrides all duplicates
                 break;
             }
         }
     }
     // only send this headers in the shutdown-function, so that it is also possible to get the contents of this buffer earlier without sending headers
     if (self::$inShutdown) {
         // force closing the connection at the client, this enables to do certain tasks (writing the cache) in the "background"
         header("Connection: close\r\n");
         // check for supported content-encodings
         if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) {
             $contentEncoding = "gzip";
         }
         if (!empty($data) && $contentEncoding) {
             ignore_user_abort(true);
             // find the content-type of the response
             $front = \Zend_Controller_Front::getInstance();
             $a = $front->getResponse()->getHeaders();
             $b = array_merge(headers_list(), $front->getResponse()->getRawHeaders());
             $contentType = null;
             // first check headers in headers_list() because they overwrite all other headers => see SOAP controller
             foreach ($b as $header) {
                 if (stripos($header, "content-type") !== false) {
                     $parts = explode(":", $header);
                     if (strtolower(trim($parts[0])) == "content-type") {
                         $contentType = trim($parts[1]);
                         break;
                     }
                 }
             }
             if (!$contentType) {
                 foreach ($a as $header) {
                     if (strtolower(trim($header["name"])) == "content-type") {
                         $contentType = $header["value"];
                         break;
                     }
                 }
             }
             // prepare the response to be sent (gzip or not)
             // do not add text/xml or a wildcard for text/* here because this causes problems with the SOAP server
             $gzipContentTypes = array("@text/html@i", "@application/json@", "@text/javascript@", "@text/css@");
             $gzipIt = false;
             foreach ($gzipContentTypes as $type) {
                 if (@preg_match($type, $contentType)) {
                     $gzipIt = true;
                     break;
                 }
             }
             // gzip the contents and send connection close tthat the process can run in the background to finish
             // some tasks like writing the cache ...
             // using mb_strlen() because of PIMCORE-1509
             if ($gzipIt) {
                 $output = "‹" . substr(gzcompress($data, 2), 0, -4) . pack('V', crc32($data)) . pack('V', mb_strlen($data, "latin1"));
                 // (although all modern browsers don't need it anymore) to work properly with google adwords check & co.
                 header("Content-Encoding: {$contentEncoding}\r\n");
             }
         }
         // no gzip/deflate encoding
         if (!$output) {
             $output = $data;
         }
         if (strlen($output) > 0) {
             // check here if there is actually content, otherwise readfile() and similar functions are not working anymore
             header("Content-Length: " . mb_strlen($output, "latin1"));
         }
         header("X-Powered-By: pimcore", true);
     }
     // return the data unchanged
     return $output;
 }