bb_send_304

Send status headers for clients supporting Conditional Get.

Description

bb_send_304( (string) $bb_last_modified ); 

The function sends the Last-Modified and ETag headers for all clients. It then checks both the If-None-Match and If-Modified-Since headers to see if the client has used them. If so, and the ETag does matches the client ETag or the last modified date sent by the client is newer or the same as the generated last modified, the function sends a 304 Not Modified and exits.

Parameters (1)

0. $bb_last_modified (string)
Last modified time. Must be a HTTP-date

Usage

  1. if ( !function_exists( 'bb_send_304' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // Last modified time. Must be a HTTP-date 
  5. $bb_last_modified = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_send_304($bb_last_modified); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_send_304( $bb_last_modified ) { 
  2. $bb_etag = '"' . md5($bb_last_modified) . '"'; 
  3. @header("Last-Modified: $bb_last_modified"); 
  4. @header("ETag: $bb_etag"); 
  5.  
  6. // Support for Conditional GET 
  7. if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); 
  8. else $client_etag = false; 
  9.  
  10. $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); 
  11. // If string is empty, return 0. If not, attempt to parse into a timestamp 
  12. $client_modified_timestamp = $client_last_modified ? bb_gmtstrtotime($client_last_modified) : 0; 
  13.  
  14. // Make a timestamp for our most recent modification...  
  15. $bb_modified_timestamp = bb_gmtstrtotime($bb_last_modified); 
  16.  
  17. if ( ($client_last_modified && $client_etag) ? 
  18. (($client_modified_timestamp >= $bb_modified_timestamp) && ($client_etag == $bb_etag)) : 
  19. (($client_modified_timestamp >= $bb_modified_timestamp) || ($client_etag == $bb_etag)) ) { 
  20. status_header( 304 ); 
  21. exit;