SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    record how many minutes is user on the page

    I have a poll on the page and I want to calculate how many minutes user needed to solve it.

    Has php any function which shows how many minutes a user has been in a page? Or is any other solution to make this?

    Thank you
    Dilster.com - Dating blog where you can find new dating tips, advices and ideas or your partner.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would need to create a timestamp when they enter the page, pass it in the form, and compare it to the current time.

  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, a timestamp on load and timestamp on submit should do it.
    eTrust : privacy and e-commerce website certification

    * Everything I post represents my personal opinion.

  4. #4
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    mysqy_query "SELECT  TIMESTAMPDIFF(MINUTE, first_visited, NOW()) AS MinsSinceLastVisit FROM yourtablename id= 'yourid' ");

    if(
    mysql_num_rows($sqlpage) > 0){
    while(
    $row1 $op->select($sqlpage)){
    $minutes_dif $row1['MinsSinceLastVisit'];
           
    $Ymin 60 24 365;
           
    $Mmin 60 24 30;
           
    $Wmin 60 24 7;
           
    $Dmin 60 24;
           
    $Hmin 60;


           
    $Y = (int)($minutes_dif $Ymin);
           
    $minutes_dif $minutes_dif % $Ymin;

           
    $MON = (int)($minutes_dif $Mmin);
           
    $minutes_dif $minutes_dif $Mmin;

           
    $W = (int)($minutes_dif $Wmin);
           
    $minutes_dif $minutes_dif $Wmin;

           
    $D = (int)($minutes_dif $Dmin);
           
    $minutes_dif $minutes_dif $Dmin;

           
    $H = (int)($minutes_dif $Hmin);
           
    $minutes_dif $minutes_dif $Hmin;

            if(
    $Y ){
                  echo 
    "$Y year(s) ";

                  }else if(
    $MON 0){
                  echo 
    "$MON month(s) ";
                  }
                  else if(
    $W 0){
                  echo 
    "$W week(s) ";
                  }
                  else if(
    $D 0){
                  echo 
    "$D day(s) ";
                  }
                  else if(
    $H 0){

                  echo 
    "$H hour(s) ";
                  }


    else if(
    $minutes_dif 0) echo "$minutes_dif minute(s) ";
    else if(
    $minutes_diff <= 0) echo "A minute ";}


  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    A bit over-the-top for a simple poll Deepson2

    @hash - sending it in the form might not be the best solution, especially if the user is aware of them being timed and want to alter the initial timestamp (easy in a form) to make it appear that they did it faster (it happens, believe it or not!)

    A session value would be better, as the user cannot access it.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you might want to expose that intentionally in order to bust users cheating

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Orrrr you could not let them cheat in the first place?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you wanted to expose them cheating, then not letting them try to cheat would fail :P

    The op is asking "how can I get php to tell me the time spent on a page", not how can I protect myself from potential poll cheaters

    But yes, session would indeed be better than post.

  9. #9
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tnx!
    Dilster.com - Dating blog where you can find new dating tips, advices and ideas or your partner.

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regardless of whether you embed the time into the form in some way, or whether you put it in a session, consider how your system will behave if a user was to refresh the page, or open another tab, or even open another window in a different browser.

  11. #11
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... or have two laptops


Bookmarks

Posting Permissions

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