Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Oct 2016
    Posts
    13
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question Time for different user locations

    Howdy
    What is the best way to show and record local time of visitors from different locations?

    I am working on a hobby site where users post a riddle and other users can answer it within a limited time.
    I do not want to show server time because it will be confusing everybody.
    Local time for each visitor is obviously different but I do not want to read it from their computers because that way they can cheat by adjusting their clock and answering the riddle.
    Any suggestions of help is greatly appreciated.
    thanks
    InvibleInk

  2. #2
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,512
    Thanks
    22
    Thanked 567 Times in 560 Posts
    if you want a limited time, show them the time left.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  3. #3
    New Coder
    Join Date
    Oct 2016
    Posts
    13
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I have to show the time question was posted and the time reply was posted. Both in their own time zone.

  4. #4
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,512
    Thanks
    22
    Thanked 567 Times in 560 Posts
    If there is no user setting of the timezone, then you need to rely on JavaScript as PHP does not know the user's timezone.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  5. #5
    New Coder
    Join Date
    Oct 2016
    Posts
    13
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks Dormilich I was leaning toward the same idea of asking the users to enter their time zones but wanted to ask some experienced people maybe there is a better way to do this.
    I guess I have to make a calculation of difference between time zone and server time and show the actual time in each location depending on visitor location. I did not want to rely on javascript or visitor computer's clock because anybody can easily cheat that.

  6. #6
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,512
    Thanks
    22
    Thanked 567 Times in 560 Posts
    I did not want to rely on javascript or visitor computer's clock because anybody can easily cheat that.
    That's not an issue since you have to provide both the posted & reply time to JS anyway. additionally, you would not read the times from the users anyway, but from your server, so cheating is not an issue.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  7. #7
    New Coder
    Join Date
    Oct 2016
    Posts
    13
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    That's not an issue since you have to provide both the posted & reply time to JS anyway. additionally, you would not read the times from the users anyway, but from your server, so cheating is not an issue.
    thanks for the reply. Do you mind explaining how to use js for this? As far as I now with js we can read the clock set by the computer not the server (which can be manipulated to cheat) and if I show the server clock we are back to square one because server shows one time and each visitor and the questions and answers would be in a different time zone.

    Lets imagine server is in PST zone (19:00) and at that time one person posts a riddle in EST zone (22:00) and 5 minutes later another person answers in MST zone (20:05). How should I use js to record their times?
    tx
    Last edited by InvibleInk; 02-20-2017 at 04:57 AM.

  8. #8
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,512
    Thanks
    22
    Thanked 567 Times in 560 Posts
    Quote Originally Posted by InvibleInk View Post
    Lets imagine server is in PST zone (19:00) and at that time one person posts a riddle in EST zone (22:00) and 5 minutes later another person answers in MST zone (20:05). How should I use js to record their times?
    tx
    Code:
    var time = new Date(<?= $timestamp * 1000 ?>);
    // format date as desired
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  9. #9
    New Coder
    Join Date
    Oct 2016
    Posts
    13
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I can't figure out how this would help the issue I described.

    1. Why would I want to multiply a variable called timestamp by 1000?
    2. you create a variable in js with the name time and assign the first value to it. How does it help any of the problems I have?
    Last edited by InvibleInk; 02-20-2017 at 10:38 AM.

  10. #10
    Regular Coder Strider64's Avatar
    Join Date
    Dec 2011
    Posts
    260
    Thanks
    5
    Thanked 33 Times in 33 Posts
    People can change javascript, but the can not change PHP.

    For example even if they did change the javascript, because the variables where PHP when you go check them they can revert back (if you coded it properly) to what they were meant to be. Putting the I cheated to I got busted and did this for nothing attitude.
    "A person who never made a mistake never tried anything new." ~ Albert Einstein https://www.pepster.com

  11. #11
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,512
    Thanks
    22
    Thanked 567 Times in 560 Posts
    Quote Originally Posted by InvibleInk View Post
    1. Why would I want to multiply a variable called timestamp by 1000?
    UNIX (and thus PHP) timestamps are in seconds, JS timestamps are in milliseconds.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •