Better headers for CGI enviroments

git-svn-id: http://svn.automattic.com/wordpress/trunk@2623 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2005-06-09 00:17:43 +00:00
parent aa209f78de
commit 09adfadae0
6 changed files with 45 additions and 41 deletions

View File

@ -7,10 +7,7 @@ else
require_once(ABSPATH . 'wp-admin/admin-functions.php');
auth_redirect();
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
nocache_headers();
update_category_cache();

View File

@ -107,14 +107,11 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
}
// Sending HTTP headers
@header('X-Pingback: '. get_bloginfo('pingback_url'));
if ( !empty($error) && '404' == $error ) {
if ( preg_match('/cgi/', php_sapi_name()) )
@header('Status: 404 Not Found');
else
@header('HTTP/1.x 404 Not Found');
status_header( 404 );
} else if ( empty($feed) ) {
@header('X-Pingback: '. get_bloginfo('pingback_url'));
@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
} else {
// We're showing a feed, so WP is indeed the only thing that last changed
@ -125,7 +122,6 @@ if ( !empty($error) && '404' == $error ) {
$wp_etag = '"' . md5($wp_last_modified) . '"';
@header("Last-Modified: $wp_last_modified");
@header("ETag: $wp_etag");
@header('X-Pingback: ' . get_bloginfo('pingback_url'));
// Support for Conditional GET
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
@ -141,17 +137,8 @@ if ( !empty($error) && '404' == $error ) {
if ( ($client_last_modified && $client_etag) ?
(($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
(($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
if ( preg_match('/cgi/',php_sapi_name()) ) {
header('Status: 304 Not Modified');
echo "\r\n\r\n";
exit;
} else {
if ( version_compare(phpversion(), '4.3.0', '>=') )
header('Not Modified', TRUE, 304);
else
header('HTTP/1.x 304 Not Modified');
exit;
}
status_header( 304 );
exit;
}
}
@ -191,10 +178,9 @@ if ( (0 == count($posts)) && !is_404() && !is_search()
&& ( isset($rewrite) || (!empty($_SERVER['QUERY_STRING']) &&
(false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
$wp_query->is_404 = true;
if ( preg_match('/cgi/', php_sapi_name()) )
@header('Status: 404 Not Found');
else
@header('HTTP/1.x 404 Not Found');
status_header( 404 );
} else {
status_header( 200 );
}
if ($pagenow != 'post.php' && $pagenow != 'edit.php') {

View File

@ -52,10 +52,7 @@ setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), time()
setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH);
setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), time() + 30000000, COOKIEPATH);
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
nocache_headers();
$location = (empty($_POST['redirect_to'])) ? $_SERVER["HTTP_REFERER"] : $_POST['redirect_to'];

View File

@ -1849,4 +1849,36 @@ function wp_remote_fopen( $uri ) {
}
}
function status_header( $header ) {
if ( 200 == $header ) {
$text = 'OK';
} elseif ( 301 == $header ) {
$text = 'Moved Permanently';
} elseif ( 302 == $header ) {
$text = 'Moved Temporarily';
} elseif ( 304 == $header ) {
$text = 'Not Modified';
} elseif ( 404 == $header ) {
$text = 'Not Found';
} elseif ( 410 == $header ) {
$text = 'Gone';
}
if ( preg_match('/cgi/',php_sapi_name()) ) {
@header("Status: $header $text");
echo "\r\n\r\n";
} else {
if ( version_compare(phpversion(), '4.3.0', '>=') )
@header($text, TRUE, $header);
else
@header("HTTP/1.x $header $text");
}
}
function nocache_headers() {
@ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
@ header('Cache-Control: no-cache, must-revalidate, max-age=0');
@ header('Pragma: no-cache');
}
?>

View File

@ -106,10 +106,7 @@ function auth_redirect() {
if ( (!empty($_COOKIE['wordpressuser_' . COOKIEHASH]) &&
!wp_login($_COOKIE['wordpressuser_' . COOKIEHASH], $_COOKIE['wordpresspass_' . COOKIEHASH], true)) ||
(empty($_COOKIE['wordpressuser_' . COOKIEHASH])) ) {
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
nocache_headers();
header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
exit();

View File

@ -4,10 +4,8 @@ require( dirname(__FILE__) . '/wp-config.php' );
$action = $_REQUEST['action'];
$error = '';
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
nocache_headers();
header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
if ( defined('RELOCATE') ) { // Move flag is set
@ -24,10 +22,7 @@ case 'logout':
wp_clearcookie();
do_action('wp_logout');
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
nocache_headers();
wp_redirect('wp-login.php');
exit();