304 Ways of PHP

Source: Internet
Author: User

General Browser request PHP is not cached unless PHP directly displays the Send head 304

if (Isset ($_server[' http_if_modified_since ')) {$browserCachedCopyTimestamp = Strtotime (Preg_replace ('/;. *$/', ', $_server[' http_if_modified_since ')), IF ($browserCachedCopyTimestamp + 604800 > Time ()) {header ("http/1.1 304 not Modified"); header ("Expires:".) Gmdate ("R", (Time () + 604800)), header ("cache-control:max-age=604800"); Exit;}} $id =i (' Get.id ', 0, ' intval '); $file = Upload_img_path. ' qccode/'. $id. '. png '; if (file_exists ($file)) {header ("last-modified:".) Gmdate (' R ', Time () ));header ("Expires:".) Gmdate ("R", (Time () + 604800)), header ("cache-control:max-age=604800");header ("Pragma:public");Header ("Content-type:image/png"); Echo file_get_contents ($file);} else{$QR = \applib\get_app_lib (' Phpqrcode ', false); $site = C (' Site_url '); $value = $site. $id. '. html '; $errorCorrectionLevel = "L"; $matrixPointSize = "4.5"; \qrcode::p ng ($value, $file, $errorCorrectionLevel, $ matrixpointsize); Echo file_get_contents ($file);}

Above is through the 304来 cache a dynamic JS, according to the file modification time to judge, here need to note, if again before there is session_start, pay attention to Session_cache_limiter, he will send a non-cached header information.

This situation needs to be able to force send a program to the public's head to circumvent, note that when sending 304, it is better to add the cache header, I can not reset the cache js, perhaps because I am a server redirection simulation of the dynamic JS bar (the request path is JS, but is generated dynamically )。

304 Ways of PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.