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 根据以下文字信息,做EA模型图
  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥60 关机时蓝屏并显示KMODE_EXCEPTION_NOT_HANDLED,怎么修?
  • ¥66 如何制作支付宝扫码跳转到发红包界面