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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question session countdown timer

    Hi,
    I am new to php, sorry if this question has already been answered somewhere else. I want to develope an online experiment and would like to have a time limit on how long a user has to complete the session. I would also need to display a timer on each of the page, and when the time runs out it should force the user to submit what he has. I can use javascript for the timer but not sure how I will store the remaining time on the server across page and still have javascript display it correctly on the nest page.

    Thanks a lot to whoever maybe able to help me with this.
    Donald

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    have it store the logon time in the database you have the login details stored in and then pass that variable to a JS script that shows the remaining time until it expires.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well since it sounds like you're using form submission to navigate from page to page, why not have the timer add itself to a hidden field in the form and send it to the next page that way? Of course, it's not very secure and people could easily spoof it, but then if that's an issue for you you're unlikely to find the answer using a forms/javascript/php solution - a java applet or something might be a better way.

  • #4
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help. I tried using the $_SESSION variable to pass the remaining time to and from the java script in each page, here is what I have:

    <form name="Tick">
    <input type="text" size="11" name="Clock">
    </form>
    <?php
    session_start();
    if (!isset($_SESSION["minutes"]) && !isset($_SESSION["seconds"]))
    {
    $_SESSION["minutes"] = 12;
    $_SESSION["seconds"] = 0;
    }

    <script type="text/javascript">
    var minutes = $_SESSION["minutes"];
    var seconds = $_SESSION["seconds"];

    function display() {
    if (seconds==0) {
    seconds=59;
    minutes = minutes-1;
    }

    if (seconds<10)
    {
    document.Tick.Clock.value=minutes+":0"+seconds;
    setTimeout("display()",1000);
    }
    else
    {
    document.Tick.Clock.value=minutes+":"+seconds;
    setTimeout("display()",1000);
    }
    seconds=seconds-1;
    }
    display();
    $_SESSION["minutes"] = minutes;
    $_SESSION["seconds"] = seconds;
    </script>
    ?>

    I am new to this so I think it is something stupide I am doing it wrong here, thanks for pointing out my mistakes.

    Donald


  •  

    Posting Permissions

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