dongpao1921 2014-03-26 12:38
浏览 85
已采纳

如何查看服务器仍处于活动状态的浏览器连接?

When money transfer occurring then if the browser closes what happen then? I mean when I am processing on server then before commit all changes I want to check the client is still online. If the suddenly closes browser then undone the changes.

My code is like :

function some(){
 do_some_stmt;//also keep track what changes has been done
 do_some_stmt;//also keep track what changes has been done
 ...............

if(connection_is_still_alive()){

// final commit
}else{
  undo_the_previous_changes();
}
}

So you can answer with php,java I think if its possible then its possible on every programming languages that design for client-server architecture .

Basically I want to know that in a middle of script is it possible to check the browser still online?

Any suggestion is welcome and thanks in advance for make me understand.

  • 写回答

2条回答 默认 最新

  • douren2831 2014-03-26 12:58
    关注

    You could make a javascript function which loads a PHP-Page in intervals.

    Something like this:

    create 3 files: file.js, onlinecheck.php and log.txt

    file.js:

    function tellTheServerThatIAmStillHere() {
      $.post('onlinecheck.php', {onlineStatus: iAmStillHere}); /* Sends a post to the file onlinecheck.php with the parameter "onlineStatus: iAmStillHere" */
      timer = window.setTimeout(tellTheServerThatIAmStillHere,8000); /* sends a new post every 8 seconds */
    }
    

    onlinecheck.php:

    <?php
      if(isset($_POST["onlineStatus"])) {
        if($_POST["onlineStatus"] == "iAmStillHere") {
          $fd = fopen("log.txt", "w");
          fwrite($fd, date("[d.m.Y - H:i:s] ").$_SERVER['REMOTE_ADDR'].": He is still here"); //Puts out something like "[26.03.2014 - 13:57:33] 127.0.0.1: He is still here"
          fclose($fd);
        }
      }
    

    Now you could check in the logfile if the browser is still online, if that's what you meant.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式