Exact time for users
I am working on a project that mainly uses javascript, css, html5. I need to specify the local time exactly, without mater, where the user is located in order to allow the user to access the module on a specific date. Let's assume 1 September
.
How can I get the exact local time for users?
Parameters:
1: use JavaScript to get the user's local time and use it.
Problem: The user can manually change the date settings on their system to change the date and access the module prematurely.
2: Use the server date to enable the module on a specific date.
Problem: The server can be located anywhere, for example, in the USA, and people in Australia will not be able to access the module, unless the date in the US is set to September 1st.
Is there any other option.
Does the client's IP address use the option?
source to share
First of all, you should always assume that the user can fake any data calculated on his side. It is more reliable to use server time.
Using IP is an option - you can find services and databases that allow you to resolve the IP address of the country it is in. Example: http://php.net/manual/en/book.geoip.php
And finally - why do you want the release date of different dates to be different for different countries? They can always use someone in another country to access the module on their behalf.
source to share
well, the user's time and time information is not included in the http request header, so php will not automatically receive this information. You can, as you said, use javascript to get the user's time, similar to what was posted here: Determine the user's timezone - this is with pure javascript, if you are using jquery or something similar you can do this very easy.
If they are registered users, you can allow them to set their timezone in your profile / settings and then just use the THAT setting, so even if they are traveling, they will always be set to their "home" timezone.
Does it help?
source to share
If the user grants permission and is using a supported browser, etc., you can get their location using navigator.geolocation.getCurrentPosition()
.
See developer.mozilla.org/en-US/docs/Web/API/Geolocation.getCurrentPosition for options and more information.
Then you can use the service provided by geonames.org . For example, http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo . This returns the time in given coordinates.
Update as per the first comment: Of course, you can never trust any data coming from outside. But there are things you can do to build trust. It was not a complete standalone solution.
source to share