skip to Main Content

I would like to put the 1/1000 second when a button is clicked into a session variable – $_SESSION['Click'] or $_COOKIE['Click']

echo '<a href="index.php?level=done"><img src="./cat.jpg" width="'.$imgwidth.'" height="'.$imgwidth.'"></a>';

The site is called again and the new level is built.
The 1/1000 second when the level is built shall be stored in another session variable $_SESSION['Begin']

Then $_SESSION['TimeNotMeasured'] += $_SESSION['Begin'] - $_SESSION['Click'] or $_COOKIE['CLick']
What would be the solution to get and store the exact time of click?

I finished the Game and it works – but I need a much better solution to measure the time between the moment when the level is finished and the milliseconds or seconds until the next level is built and ready.

2

Answers


  1. Chosen as BEST ANSWER

    Easier than I thought / Made a tested and working Solution:

    function myFunction() 
    {
        const d = new Date();
        let time = d.getTime();
        d.setTime(time + 5000);
        let expires = "expires="+ d.toUTCString();
        document.cookie = "time="+time+";"+expires+";path=/";
        window.open('index.php?level=yes',"_top");
    }
    echo '<span id="tick" onclick="myFunction()"><img src="./cat_asis.jpg" width="'.$imgwidth.'" height="'.$imgwidth.'"></span>';
    

  2. You’re talking about things that happen in the browser:

    • Clicks.
    • Levels that finish.

    You therefore have to measure these things in the browser, not in PHP. You could for instance use performance.now(), like so:

    const t0 = performance.now();
    doSomething();
    const t1 = performance.now();
    console.log(`Call to doSomething took ${t1 - t0} milliseconds.`);
    

    After you’ve timed it you can send the information back to the server, with a delay and store it there.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search