How to use etags in a PHP file?
Create / edit your .htaccess file and add the following:
FileETag MTime Size
Either place the following inside a function or put it at the top of the PHP file that you need etags to work on:<?php
$file = 'myfile.php';
$last_modified_time = filemtime($file);
$etag = md5_file($file);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
exit;
}
?>
PHP REST API with ETAG support?
You can find the corresponding request headers in $_SERVER
If-Match
. Is the key HTTP_IF_MATCH
, If-None-Match
corresponds to HTTP_IF_NONE_MATCH
.
In order to send proper ETags to the client use the ETag
header like header( 'ETag: ' . generateEtag() );
. You just need to ensure that your ETag represents the response of the service properly.
Grab text between specific tags in PHP file
This is how you would escape the regex:
foreach (glob("template/*.php") as $fn) {
$file = file_get_contents($fn);
preg_match_all("#\{\('(\w+)'\)}#", $file, $matches);
print_r($matches);
}
Eugen has shown how to match the PHP/PI <?
tags and /*
comment sections as well. You may just need \s*
in between those.
Related Topics
How to Call Curl_Setopt with Curlopt_Httpheader Multiple Times to Set Multiple Headers
Upload Progress Using Pure PHP/Ajax
What Is the Correct Format for a Blowfish Salt Using PHP's Crypt
How to Resize and Convert an Uploaded Image to a Png Using Gd
How to Run PHP File Using Cron Jobs
Laravel Unexpected Redirects ( 302 )
Rounding Up to the Second Decimal Place
Wordpress Paginate_Links - How to Use It
Efficient Reloading Data/Pushing Data from Server to Client
How to Send HTML Mails Using Pear Mail
PHP Class: Global Variable as Property in Class
How to Wrap Text Using Imagick in PHP So That It Is Drawn as Multiline Text
Order Properties Should Not Be Accessed Directly - Woocommerce 3.0
How to Deal with "Method Not Found in Class" Warning for Magically Implemented Methods
MySQL and Query to Satisfy on Same Column
Include Just Files in Scandir Array