dqdfpmmi022763 2016-06-04 14:30
浏览 6

如何定义客户端访问网站的时间

I have a site and I want to measure how long a client was connected to my site, one hour or two hour... or? how is it possible? can someone help me in this regard. it will be appreciated.

  • 写回答

1条回答 默认 最新

  • douba8048 2016-06-04 14:46
    关注

    As mentioned in the comments, it's best to use analytic software but if you are looking for something simple (or just learning experience)

    <?php
    
    session_start();
    
    if(!isset($_SESSION['sessionId'])) // No session, first time (subject to session timeout)
    {
        mysqli_query("INSERT INTO visitor_sessions(`started_on`, `last_checkin`) (" . time() . ", " . time() .")");
    $_SESSION['sessionId'] = mysqli_insert_id();    // start the 'visiting session'
     }
    else
    {
        mysqli_query("UPDATE  visitor set `last_checkin` = " . time() . " WHERE id = " .$_SESSION['sessionId']); // Update last checkin
    }
    
    ?>
    

    visitor_sessions is a table with 3 columns, id, started_on and last_checkin (timestamps).

    You can include this script in your pages thus updating last check_in with each new page opened or have jquery call it every x seconds to maintain time even if they just view a page.

    PS: Code was not tested but this is the general idea

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号