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条)

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了