Three implementation methods for real-time countdown of php _ PHP Tutorial

Source: Internet
Author: User
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...

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.