nocache_headers()阻止不同浏览器的缓存

目录

描述

译文

设置页头,使之阻止不同浏览器的缓存。

不同浏览器支持不同的nocache页头,因此必须要发送多个页头才能保证所有浏览器都 不进行缓存。

原文

Sets the headers to prevent caching for the different browsers.

Different browsers support different nocache headers, so several headers must be sent so that all of them get the point that no caching should occur.

nocache_headers() 描述

用法

<?php nocache_headers() ?>

nocache_headers() 用法

参数

None.

nocache_headers() 参数

返回值

(void) 

This function does not return a value.

nocache_headers() 返回值

历史

添加于 版本: 2.0.0

nocache_headers() 历史

源文件

nocache_headers() 函数的代码位于 wp-includes/functions.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Set the headers to prevent caching for the different browsers.
 *
 * Different browsers support different nocache headers, so several
 * headers must be sent so that all of them get the point that no
 * caching should occur.
 *
 * @since 2.0.0
 *
 * @see wp_get_nocache_headers()
 */
function nocache_headers() {
	$headers = wp_get_nocache_headers();

	unset( $headers['Last-Modified'] );

	// In PHP 5.3+, make sure we are not sending a Last-Modified header.
	if ( function_exists( 'header_remove' ) ) {
		@header_remove( 'Last-Modified' );
	} else {
		// In PHP 5.2, send an empty Last-Modified header, but only as a
		// last resort to override a header already sent. #WP23021
		foreach ( headers_list() as $header ) {
			if ( 0 === stripos( $header, 'Last-Modified' ) ) {
				$headers['Last-Modified'] = '';
				break;
			}
		}
	}

	foreach( $headers as $name => $field_value )
		@header("{$name}: {$field_value}");
}

nocache_headers() 源文件