Php real-time countdown implementation methods. Requirements: 1. display of real-time countdown in hours and minutes. 2. modifying the date and time on the user end does not affect the normal display of the countdown (that is, the server time prevails ). In fact, this requirement:
1. display of real-time countdown in hours, minutes, and seconds is required.
2. modifying the date and time on the user end does not affect the normal display of the countdown (that is, the server time prevails ). In fact, this is the same as the requirements for many system time restrictions such as exams.
Solution:
1. you cannot use ajax to obtain the server time every second. Therefore, real-time countdown must be implemented using javascript. This is a simple example.
2. now the problem is to solve the impact of modifying the date and time on the display of the client. The solution is to calculate the time difference between the user end time and the server time, which completely solves the problem. you only need to run php once, and the real-time countdown time is synchronized with the server time. The theory is synchronous, but the actual test will have an error of 1 second (the specific reason is that it is related to the network speed, the faster the network speed, the smaller the error ), but this will never affect our above requirements.
Code 1:
Code 2: modified some bugs in code 1:
Code 3 has different ideas and is much simpler:
Tip 1: It takes an hour, minute, and second to display the real-time countdown. 2. modifying the date and time on the user end does not affect the normal display of the countdown (that is, the server time prevails ). Actually this...