batcache::do_headers PHP Method

do_headers() public method

public do_headers ( $headers1, $headers2 = [] )
    function do_headers($headers1, $headers2 = array())
    {
        // Merge the arrays of headers into one
        $headers = array();
        $keys = array_unique(array_merge(array_keys($headers1), array_keys($headers2)));
        foreach ($keys as $k) {
            $headers[$k] = array();
            if (isset($headers1[$k]) && isset($headers2[$k])) {
                $headers[$k] = array_merge((array) $headers2[$k], (array) $headers1[$k]);
            } elseif (isset($headers2[$k])) {
                $headers[$k] = (array) $headers2[$k];
            } else {
                $headers[$k] = (array) $headers1[$k];
            }
            $headers[$k] = array_unique($headers[$k]);
        }
        // These headers take precedence over any previously sent with the same names
        foreach ($headers as $k => $values) {
            $clobber = true;
            foreach ($values as $v) {
                header("{$k}: {$v}", $clobber);
                $clobber = false;
            }
        }
    }

Usage Example

Exemplo n.º 1
0
if ($batcache->do !== false && isset($batcache->cache['version']) && $batcache->cache['version'] < $batcache->url_version) {
    $batcache->genlock = wp_cache_add("{$batcache->url_key}_genlock", 1, $batcache->group, 10);
}
// Temporary: remove after 2010-11-12. I added max_age to the cache. This upgrades older caches on the fly.
if (!isset($batcache->cache['max_age'])) {
    $batcache->cache['max_age'] = $batcache->max_age;
}
// Did we find a batcached page that hasn't expired?
if (isset($batcache->cache['time']) && !$batcache->genlock && time() < $batcache->cache['time'] + $batcache->cache['max_age']) {
    // Issue redirect if cached and enabled
    if ($batcache->cache['redirect_status'] && $batcache->cache['redirect_location'] && $batcache->cache_redirects) {
        $status = $batcache->cache['redirect_status'];
        $location = $batcache->cache['redirect_location'];
        // From vars.php
        $is_IIS = strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false;
        $batcache->do_headers($batcache->headers);
        if ($is_IIS) {
            header("Refresh: 0;url={$location}");
        } else {
            if (php_sapi_name() != 'cgi-fcgi') {
                $texts = array(300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect');
                $protocol = $_SERVER["SERVER_PROTOCOL"];
                if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
                    $protocol = 'HTTP/1.0';
                }
                if (isset($texts[$status])) {
                    header("{$protocol} {$status} " . $texts[$status]);
                } else {
                    header("{$protocol} 302 Found");
                }
            }