Home > Daily Programming > PHP Knowledge > How to get the last modification time of the current page in PHP

How to get the last modification time of the current page in PHP

藏色散人
Release: 2021-01-11 10:50:08
Original
7941 people have browsed it

PHP gets the last modification time of the current page. We can achieve this through the date and getlastmod functions in PHP.

How to get the last modification time of the current page in PHP

Let's use a simple code example to introduce to you the implementation method of getting the last modification time of the page in PHP.

The code example is as follows:

<?php
echo "最后一次修改的时间为:" . date ("Y-m-d H:i:s.", getlastmod())."\n";
Copy after login

The output result is as follows:

How to get the last modification time of the current page in PHP

Here we get the last modified time of the current page: 2019- 01-25 10:55:13.

Main function introduction:

date() function is used to format a local time/date

date ( string $format [, int $timestamp ] ) : string
Copy after login

returns The integer timestamp is a string generated according to the given format string. If no timestamp is given, the local current time is used. In other words, timestamp is optional and the default value is time().

Since PHP 5.1.1 there are several useful constants that can be used as standard date/time formats to specify the format parameter. The timestamp of the time when the request was initiated is stored in $_SERVER['REQUEST_TIME'].

Note: The typical range of valid timestamps is December 13, 1901 20:45:54 GMT to January 19, 2038 03:14:07 GMT. (This range conforms to the minimum and maximum values ​​of 32-bit signed integers). However, prior to PHP 5.1 this range was limited to January 1, 1970 to January 19, 2038 on some systems such as Windows.

getlastmod() function is used to get the last modification time of the page.

getlastmod ( void ) : int
Copy after login

Get the last modification time of the executed main script.

Return value, returns the last modified time of the current page. This value is a Unix timestamp that can be passed into date(). Returns FALSE on error.

This article is an introduction to the method of getting the last modification time of the current page in PHP. It is very simple and easy to understand. I hope it will be helpful to friends in need!

The above is the detailed content of How to get the last modification time of the current page in PHP. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template