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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I need a timer..

    Hey, I'm in need for a PHP timer that will count the time taken for a person sat on a page.

    Here's the best example I can get you:
    Someone goes to a sertain page, say timer.php and on that page, there is a questionaire that they need to fill in. When they click Submit, I want it to be sent with the answers that they filled in.

    If you nee anymore specificness, I shall try my hardest to reply.

    Thanks.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    stamp the time ie time(); (curently will display 1251289587)
    post it with the form i.e
    PHP Code:
    page.php?time=<?php echo time(); ?>
    then use time again on page.php (now would be 1251289686) and compare the difference. Look up time() on www.php.net

    PHP Code:
    <?php
        
    if(isset($_POST['submit']))
    {
        if(isset(
    $_GET['time']))
        {
            
    $difference = (time()-$_GET['time']);
            echo 
    "Time diff in seconds: ".$difference." secs";
        }
    }

    ?>

    <form method="post" action="index.php?time=<?php echo time(); ?>">
    <input type="submit" name="submit" value="submit">
    </form>
    or more:

    PHP Code:
    <?php
        
    if(isset($_POST['submit']))
    {
        if(isset(
    $_GET['time']))
        {
            
    $difference = (time()-$_GET['time']);
            if(
    $difference>=3600)//1 hour
            
    {
                echo 
    "Sorry timed out";    
            }
            else
            {
                echo 
    "Time diff in seconds: ".$difference." secs";
            }
        }
    }

    ?>
    Last edited by Fou-Lu; 08-26-2009 at 03:51 PM.


  •  

    Posting Permissions

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