Jump to content

window close?


adamlacombe

Recommended Posts

I have googled everything possible to find the answer to this.

I need to use javascript to close a window, but when it closes I need it to run some php:

<?php
if($windowcloses){
   $fp = fopen("chat.html", 'a');
   fwrite($fp, "<i>User <a href='index.php?action=profile&username=". $_SESSION['username'] ."'>". $_SESSION['username'] ."</a> has left the chat session.</i><br>");
   fclose($fp);
?>

 

is that possible, and if so what is the code I need to use?

Thanks in advanced!

Link to comment
https://forums.phpfreaks.com/topic/174928-window-close/
Share on other sites

It's impossible to be 100% accurate in knowing if a user closes the page. If you're building a chat application you'll be constantly polling the server, correct? So have the server check if the user is still polling, you can assume if after xx seconds the user hasn't polled that they're no longer connected. You shouldn't rely on the client to provide disconnection/connection messages, user the serverside to do that.

Link to comment
https://forums.phpfreaks.com/topic/174928-window-close/#findComment-921889
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.