php - Countdown timer on my website changes if I change my computer's time?
Hi I need help regarding the following issue:
My website has a timer countdown running. Actually in my admin panel I set a date and time for a process to begin and when i hit on save the timer countdown starts in my website.
Example : Say now my current time is 1pm. Now for example in my admin panel I am creating an event now. The start of the event is tomorrow 1pm. So now in my admin panel I select the start time of event to tomorrow 1 pm. Now the time remaining for the event is 24 hours. So now in my website the countdown timer starts for the event like :
Time left for the event
: 24h:0m:0s and this timer goes in decreasing order. Now the issue is that the timer is taking the time from my computer. If I change the time on my computer, the count down timer on my website also changes.
Please help me out regarding this on how to use the server time for my website's timer so the time is same for all the users irrespective of their computer's date and time.
I also heard a concept of stop watch?
Please help me out
Answer
Solution:
If your code is on server the only reason for showing local time is you are using Javascript for time because Javascript fetch time from local system.
Answer
Solution:
just set these at top of your php code and calculate or do whatever you want with it afterwards
Answer
Solution:
JavaScript traditionally runs client-side, meaning in the user's browser whereas PHP runs server side, ie. it will fetch time from your server. In your case, you need the time to be same for all users of your website which means you need a server side code
In short: