PHP static file return_PHP tutorial
php static files return
Sometimes some static files (such as pictures) will be output by php, and you will find that the request is 200, and the static files go to the server every time The request is too wasteful of resources. How to let the browser cache the image? We need to output 304 in php.
We can use HTTP_IF_MODIFIED_SINCE in php combined with etag to do this. Etag does not have a clearly defined format. We can use the md5 value of the file modification time. The code is as follows:
The code is as follows:
private function _addEtag($file) {
$last_modified_time = filemtime($file);
$etag = md5_file($file);
// always send headers
Header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("Etag: $etag");
// exit if not modified
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;
}
}
It can be called in the code before static files (such as pictures) are output.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP Tips: Quickly implement the function of returning to the previous page. In web development, we often encounter the need to implement the function of returning to the previous page. Such operations can improve the user experience and make it easier for users to navigate between web pages. In PHP, we can achieve this function through some simple code. This article will introduce how to quickly implement the function of returning to the previous page and provide specific PHP code examples. In PHP, we can use $_SERVER['HTTP_REFERER'] to get the URL of the previous page

MySQL is a widely used relational database management system for storing and managing data. When we want to insert new data into a database table, we usually use the INSERT statement. In MySQL, when the INSERT statement is executed to successfully insert data, a result will be returned, which is the result of the insertion operation. In this article, we will discuss in detail the results returned by MySQL after inserting data and provide some specific code examples. 1. The result returned after inserting data is in MySQL. When successfully executed

How to use Vue to implement the special effect of returning to the previous page. In front-end development, we often encounter situations where we need to return to the previous page. By adding a back button, you can provide a better user experience. This article will introduce how to use the Vue framework to achieve the special effect of returning to the previous page, and provide corresponding code examples. First, in the Vue project, you need to create a page as the previous page. We can set routing through VueRouter, and each route corresponds to a component. In the previous page, we can add a back button and pass the click event

Discuss a problem based on the extended matrix. An extended matrix is a matrix whose size increases by some factor. Here we have a character matrix whose size is expanded by a multiple of 2, i.e. if the size of the original matrix is N*N, then the size of the expanded matrix becomes 2N*2N. We are given a character sequence located at (i, j), and we need to return the character sequence located at (i, (j-N-1)%N). Let's understand by visualizing some initial expansion matrices. GivenMatrix->[a,b][c,d],2X2matrixMultiplyingwith{a,b,c,d}AX[a,b]BX[a,b]CX[a,b]DX[a,b][c ,d]

We can use array loop to return the largest element from the list. This is mainly achieved by comparing models. In a list, the largest number is compared to all elements in the list. The procedure will consider 'n' as input quantity and store it as data value in the array. Afterwards, the program will display the largest element on the output console after the loop ends. In this article, we will help you understand and write some Java code through which you can find the largest element from an array list. How to select the largest number from an array using Java? Wecanfindalargestnumberbysortinganarray.TodefineavoidArrayL

You need to make a function that returns 2 for input 1 and 1 for input 2. This function can be made in various ways depending on the logic you use. The simplest way is to use a conditional statement, if the number is 1, return 2, otherwise return 1, other ways include using math operations (any kind will work) and XOR operations. Example #include<stdio.h>//Method1usingtheifstatementintreverseif(intx){ if(x==1)return2; elsereturn1;}/

Custom functions in PHP can return values of specified types through the return statement, including strings, numbers, arrays, and objects. Practical case: -Return string: functiongreet($name){return "Hello,$name!";} -Return array: functionget_user_data($id){return["name"=>"John","email"=> "john@example.com"];}

The steps for using function return values in PHP include: using function to declare a function; using the return statement to return results; calling the function and capturing the return value.
