Discussion:
close the browser
hadi
2014-06-24 16:08:34 UTC
Permalink
Hi,

Is there's any way to run script when user close the browser in php ?

Thanks .
Stuart Dallas
2014-06-24 16:15:39 UTC
Permalink
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Not reliably. What is it that you are trying to achieve?

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
hadi
2014-06-24 16:48:50 UTC
Permalink
Post by Stuart Dallas
Not reliably. What is it that you are trying to achieve?
Im building captive portal (internet hostspot) I would like to determine if
connection close between the user and server. If so run a script.
What do you suggest to do ?
Post by Stuart Dallas
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Not reliably. What is it that you are trying to achieve?
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Stuart Dallas
2014-06-24 16:51:52 UTC
Permalink
Post by hadi
Post by Stuart Dallas
Not reliably. What is it that you are trying to achieve?
Im building captive portal (internet hostspot) I would like to determine if
connection close between the user and server. If so run a script.
What do you suggest to do ?
I get that, but why do you want to run a script? Based on your previous
emails it looks like you're trying to manually expire a session. Sessions
usually expire due to a timeout since the last request, and I've never come
across a reason to do it any other way. So again, what is it that you are
actually trying to achieve?

If you want to apply a more complicated set of session expiry rules you can
do so with a custom session handler, but I would question the need for such
a thing.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Post by hadi
Post by Stuart Dallas
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Not reliably. What is it that you are trying to achieve?
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
David OBrien
2014-06-24 17:01:51 UTC
Permalink
Post by Stuart Dallas
Post by hadi
Post by Stuart Dallas
Not reliably. What is it that you are trying to achieve?
Im building captive portal (internet hostspot) I would like to determine
if
Post by hadi
connection close between the user and server. If so run a script.
What do you suggest to do ?
I get that, but why do you want to run a script? Based on your previous
emails it looks like you're trying to manually expire a session. Sessions
usually expire due to a timeout since the last request, and I've never come
across a reason to do it any other way. So again, what is it that you are
actually trying to achieve?
If you want to apply a more complicated set of session expiry rules you can
do so with a custom session handler, but I would question the need for such
a thing.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Post by hadi
Post by Stuart Dallas
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Not reliably. What is it that you are trying to achieve?
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
I'd start with something you can read and try and understand and then
modify to suit your use.

http://www.andybev.com/index.php/Using_iptables_and_PHP_to_create_a_captive_portal

http://aryo.info/labs/captive-portal-using-php-and-iptables.html
hadi
2014-06-24 17:18:30 UTC
Permalink
Post by Stuart Dallas
I get that, but why do you want to run a script? Based on your previous
emails it looks like you're trying to manually expire a session. Sessions
usually expire due to a timeout since the last request, and I've never >come
across a reason to do it any other way. So again, what is it that you are
actually trying to achieve?
If you want to apply a more complicated set of session expiry rules you can
do so with a custom session handler, but I would question the need for such a
thing.
Well im trying to achieve one thing here. If a user is logged in and if he
try to logged in again from different pc with the same username/password it
well flag him out. Because he already logged in.
About connection close, when the user close the connection it well clear the
flag.
So what do I use to accomplish this ?
Post by Stuart Dallas
Not reliably. What is it that you are trying to achieve?
Im building captive portal (internet hostspot) I would like to determine if
connection close between the user and server. If so run a script.
What do you suggest to do ?

I get that, but why do you want to run a script? Based on your previous emails
it looks like you're trying to manually expire a session. Sessions usually
expire due to a timeout since the last request, and I've never come across a
reason to do it any other way. So again, what is it that you are actually
trying to achieve?

If you want to apply a more complicated set of session expiry rules you can do
so with a custom session handler, but I would question the need for such a
thing.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Post by Stuart Dallas
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Not reliably. What is it that you are trying to achieve?
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Stuart Dallas
2014-06-24 17:30:21 UTC
Permalink
Post by Stuart Dallas
Post by Stuart Dallas
I get that, but why do you want to run a script? Based on your previous
emails it looks like you're trying to manually expire a session. Sessions
usually expire due to a timeout since the last request, and I've never come
across a reason to do it any other way. So again, what is it that you are
actually trying to achieve?
If you want to apply a more complicated set of session expiry rules you
can
Post by Stuart Dallas
do so with a custom session handler, but I would question the need for
such a
Post by Stuart Dallas
thing.
Well im trying to achieve one thing here. If a user is logged in and if he
try to logged in again from different pc with the same username/password it
well flag him out. Because he already logged in.
About connection close, when the user close the connection it well clear the
flag.
So what do I use to accomplish this ?
I would start with a custom session handler. Possibly something similar to
this: http://3ft9.com/mysql-sessions/

Modify the methods that write the data to MySQL so it first extracts the
username and stores that in a separate field so you can do lookups on that.

Set the lifetime to something relatively short (say 60 seconds), then have
a webpage that the user must keep open that is making a request to the
server at roughly half that interval (e.g. every 30 seconds).

Modify the Session::gc method so it does what's necessary to cleanup the
network config when a session expires.

Add a method so your login system can query the session store for existing
users with that username, or alternatively modify the Session::write method
to refuse to store a session if there's already a session for that username.

Using a timeout rather than trying to detect when the user closes their
browser is preferable primarily due to the unreliability of that detection.
A number of browsers have rules around the use of the onunload event that
may prevent you from seeing a particular user disconnect.

Personally I would be looking in to implementing this at the network level
rather than PHP. The network must be able to detect when a device drops off
the network, and that would probably be a better place to implement the
cleanup.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
hadi
2014-06-24 17:44:20 UTC
Permalink
Post by Stuart Dallas
Using a timeout rather than trying to detect when the user closes their
browser is preferable primarily due to the unreliability of that detection.
I can't use time out. What if the user want to stay online more time ?
Post by Stuart Dallas
Post by Stuart Dallas
Post by Stuart Dallas
I get that, but why do you want to run a script? Based on your
previous emails it looks like you're trying to manually expire a
session. Sessions usually expire due to a timeout since the last
request, and I've never come across a reason to do it any other way.
So again, what is it that you are actually trying to achieve?
If you want to apply a more complicated set of session expiry rules you
can
Post by Stuart Dallas
do so with a custom session handler, but I would question the need for
such a
Post by Stuart Dallas
thing.
Well im trying to achieve one thing here. If a user is logged in and
if he try to logged in again from different pc with the same
username/password it well flag him out. Because he already logged in.
About connection close, when the user close the connection it well
clear the flag.
So what do I use to accomplish this ?
I would start with a custom session handler. Possibly something similar to
this: http://3ft9.com/mysql-sessions/
Modify the methods that write the data to MySQL so it first extracts the
username and stores that in a separate field so you can do lookups on that.
Set the lifetime to something relatively short (say 60 seconds), then have a
webpage that the user must keep open that is making a request to the
server at roughly half that interval (e.g. every 30 seconds).
Modify the Session::gc method so it does what's necessary to cleanup the
network config when a session expires.
Add a method so your login system can query the session store for existing
users with that username, or alternatively modify the Session::write method
to refuse to store a session if there's already a session for that username.
Using a timeout rather than trying to detect when the user closes their
browser is preferable primarily due to the unreliability of that detection.
A number of browsers have rules around the use of the onunload event that
may prevent you from seeing a particular user disconnect.
Personally I would be looking in to implementing this at the network level
rather than PHP. The network must be able to detect when a device drops
off the network, and that would probably be a better place to implement the
cleanup.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Stuart Dallas
2014-06-24 18:12:03 UTC
Permalink
Post by Stuart Dallas
Post by Stuart Dallas
Using a timeout rather than trying to detect when the user closes their
browser is preferable primarily due to the unreliability of that
detection.
I can't use time out. What if the user want to stay online more time ?
That's why you have the page that must remain open and is requesting a page
on the server every 30 seconds - that's what's keeping the session alive.

This should be implemented at the network level so I encourage you to
investigate what's possible there.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Christoph Becker
2014-06-24 18:13:18 UTC
Permalink
Post by hadi
Post by Stuart Dallas
Using a timeout rather than trying to detect when the user closes their
browser is preferable primarily due to the unreliability of that detection.
I can't use time out. What if the user want to stay online more time ?
Stuart has explained that in his post. Please read and try to
understand what he wrote.

BTW: please do not top-post. See
<http://git.php.net/?p=php-src.git;a=blob_plain;f=README.MAILINGLIST_RULES;hb=HEAD>.
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2014-06-24 16:16:44 UTC
Permalink
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Yes: http://www.php.net//manual/en/function.ignore-user-abort.php
Stuart Dallas
2014-06-24 16:26:31 UTC
Permalink
Post by Aziz Saleh
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Yes: http://www.php.net//manual/en/function.ignore-user-abort.php
That's detecting a client disconnection, not the browser being closed.
While closing the browser will also close the connection, it's not the only
action that will do so.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Aziz Saleh
2014-06-24 16:39:49 UTC
Permalink
Post by Stuart Dallas
Post by Aziz Saleh
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Yes: http://www.php.net//manual/en/function.ignore-user-abort.php
That's detecting a client disconnection, not the browser being closed.
While closing the browser will also close the connection, it's not the only
action that will do so.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Stuart:

Here is what I can think of:

1) User closes the browser.
2) Internet is disconnected.
3) Computer shuts of.
4) Intermittent connection.

I could be missing a few (if so, please let us know which). Either way,
they all are pretty much connection lost which I am 90% is what the OP was
thinking of (probably didn't think of a way to do something for the other
cases).
Stuart Dallas
2014-06-24 16:43:50 UTC
Permalink
Post by Aziz Saleh
Post by Stuart Dallas
Post by Aziz Saleh
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Yes: http://www.php.net//manual/en/function.ignore-user-abort.php
That's detecting a client disconnection, not the browser being closed.
While closing the browser will also close the connection, it's not the only
action that will do so.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
1) User closes the browser.
2) Internet is disconnected.
3) Computer shuts of.
4) Intermittent connection.
I could be missing a few (if so, please let us know which). Either way,
they all are pretty much connection lost which I am 90% is what the OP was
thinking of (probably didn't think of a way to do something for the other
cases).
Your 90% scenario is actually...

Page completely loaded so the script has ended => User closes browser

Using ignore_user_abort does not get anywhere close to doing what the OP
wants. Not that we actually know what the OP really wants until he tells
us. I'm yet to hear of a legitimate reason to want some PHP to execute when
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Aziz Saleh
2014-06-24 16:46:52 UTC
Permalink
Post by Stuart Dallas
Post by Aziz Saleh
Post by Stuart Dallas
Post by Aziz Saleh
Post by hadi
Hi,
Is there's any way to run script when user close the browser in php ?
Thanks .
Yes: http://www.php.net//manual/en/function.ignore-user-abort.php
That's detecting a client disconnection, not the browser being closed.
While closing the browser will also close the connection, it's not the only
action that will do so.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
1) User closes the browser.
2) Internet is disconnected.
3) Computer shuts of.
4) Intermittent connection.
I could be missing a few (if so, please let us know which). Either way,
they all are pretty much connection lost which I am 90% is what the OP was
thinking of (probably didn't think of a way to do something for the other
cases).
Your 90% scenario is actually...
Page completely loaded so the script has ended => User closes browser
Using ignore_user_abort does not get anywhere close to doing what the OP
wants. Not that we actually know what the OP really wants until he tells
us. I'm yet to hear of a legitimate reason to want some PHP to execute when
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Ah I see now what the OP means. I guess my mind always jumps to PHP
solutions to the issue, when indeed the issue here was to do with the page
onunload event. My bad.
hadi
2014-06-24 17:27:38 UTC
Permalink
I used this code but doesn't seems to work I close the browser but nothing
happen here. Can somebody clarifying my code please.

<html>
<body>
<?php


if (connection_aborted())

{

file_put_contents('/tmp/phptest1234.txt', 'test');

}

echo "<br>Hi\n</br>";


?>

</body>
</html>
Stuart Dallas
2014-06-24 17:34:11 UTC
Permalink
Post by hadi
I used this code but doesn't seems to work I close the browser but nothing
happen here. Can somebody clarifying my code please.
<html>
<body>
<?php
if (connection_aborted())
{
file_put_contents('/tmp/phptest1234.txt', 'test');
}
echo "<br>Hi\n</br>";
?>
</body>
</html>
PHP runs on the server, generates the page, and returns it to the browser.
Once that process has completed PHP is out of the picture. For the above
code to work you would need to stop the request after PHP has started
processing but before the call to connection_aborted, which will be a very
small amount of time.

If this is your level of understanding of the way PHP works then I'd
suggest finding an off-the-shelf captive portal and using that rather than
attempting to write your own. Or, learn a lot more about PHP before
attempting something that is relatively complicated to achieve.

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Tim Streater
2014-06-24 18:53:00 UTC
Permalink
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window, and then closes the browser window, they will expect that what they typed will show up again when they restart the app. I use the onbeforeunload event in the browser to handle this, along with a (rare) synchronous ajax request to run a PHP termination script.
--
Cheers -- Tim
Stuart Dallas
2014-06-24 19:09:56 UTC
Permalink
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window,
and then closes the browser window, they will expect that what they typed
will show up again when they restart the app. I use the onbeforeunload
event in the browser to handle this, along with a (rare) synchronous ajax
request to run a PHP termination script.
That's certainly a solution to that problem. In the past I've used
onbeforeunload to check if the user has edited anything and display a
confirmation dialog, but never to make a request to the server. I'm
struggling to identify why, but doing that just doesn't sit right with me.
It may be because I've heard that the event is not reliably thrown by all
browsers in all situations as a result of various spammy behaviour by dodgy
sites in the past. That view may well be out of date now. Have you seen any
problems like that?

-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
Jim Giner
2014-06-24 19:14:14 UTC
Permalink
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window, and
then closes the browser window, they will expect that what they typed
will show
up again when they restart the app. I use the onbeforeunload event in the
browser to handle this, along with a (rare) synchronous
ajax request to run a PHP termination script.
Post by Tim Streater
--
Cheers -- Tim
Really - you expect something that was being typed just before closing
to be (magically?) present when you re-open the browser to that page?

I would never expect something like to occur in any kind of computer
application that (most likely) has procedures to be followed to properly
use that page and save that data before closing it. Failure to follow
the rules and an abrupt closure of the page/browser should not retain
whatever I was doing and I can't fault it.

Granted - you are doing this for you appls. but the mere fact that you
have done so surprises me. I would never think to provide that service
on my appls.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Shawn McKenzie
2014-06-24 20:13:29 UTC
Permalink
DELETE FROM `php-general` WHERE `from` = 'hadi' OR `from` = 'almarzuki2011@
hotmail.com'
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
Post by Stuart Dallas
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window, and
then closes the browser window, they will expect that what they typed will
show
up again when they restart the app. I use the onbeforeunload event in the
browser to handle this, along with a (rare) synchronous
ajax request to run a PHP termination script.
Post by Stuart Dallas
--
Cheers -- Tim
Really - you expect something that was being typed just before closing
to be (magically?) present when you re-open the browser to that page?
I would never expect something like to occur in any kind of computer
application that (most likely) has procedures to be followed to properly
use that page and save that data before closing it. Failure to follow the
rules and an abrupt closure of the page/browser should not retain whatever
I was doing and I can't fault it.
Granted - you are doing this for you appls. but the mere fact that you
have done so surprises me. I would never think to provide that service on
my appls.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
2014-06-24 21:25:58 UTC
Permalink
Post by Shawn McKenzie
hotmail.com'
lol, tell us how you really feel!
Post by Shawn McKenzie
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
Post by Stuart Dallas
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window, and
then closes the browser window, they will expect that what they typed will
show
up again when they restart the app. I use the onbeforeunload event in the
browser to handle this, along with a (rare) synchronous
ajax request to run a PHP termination script.
Post by Stuart Dallas
--
Cheers -- Tim
Really - you expect something that was being typed just before closing
to be (magically?) present when you re-open the browser to that page?
I would never expect something like to occur in any kind of computer
application that (most likely) has procedures to be followed to properly
use that page and save that data before closing it. Failure to follow the
rules and an abrupt closure of the page/browser should not retain whatever
I was doing and I can't fault it.
Granted - you are doing this for you appls. but the mere fact that you
have done so surprises me. I would never think to provide that service on
my appls.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
hadi
2014-06-25 00:12:26 UTC
Permalink
Post by Jim Lucas
lol, tell us how you really feel!
By the way I got unsubscribe email.
Post by Jim Lucas
Post by Shawn McKenzie
DELETE FROM `php-general` WHERE `from` = 'hadi' OR `from` =
lol, tell us how you really feel!
Post by Shawn McKenzie
On Tue, Jun 24, 2014 at 2:14 PM, Jim Giner
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
Post by Stuart Dallas
a user closes the browser, so chances are there's a better way to
achieve what he actually wants.
I use that in my app. If the user has been typing into an editing window, and
then closes the browser window, they will expect that what they typed
will show up again when they restart the app. I use the
onbeforeunload event in the browser to handle this, along with a
(rare) synchronous ajax request to run a PHP termination script.
Post by Stuart Dallas
--
Cheers -- Tim
Really - you expect something that was being typed just before closing
to be (magically?) present when you re-open the browser to that page?
I would never expect something like to occur in any kind of computer
application that (most likely) has procedures to be followed to
properly use that page and save that data before closing it. Failure
to follow the rules and an abrupt closure of the page/browser should
not retain whatever I was doing and I can't fault it.
Granted - you are doing this for you appls. but the mere fact that
you have done so surprises me. I would never think to provide that
service on my appls.
--
http://www.php.net/unsub.php
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--
http://www.php.net/unsub.php
t***@weberpafrica.com
2014-06-28 16:18:33 UTC
Permalink
Post by Shawn McKenzie
hotmail.com'
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
Post by Stuart Dallas
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window, and
then closes the browser window, they will expect that what they typed will
show
up again when they restart the app. I use the onbeforeunload event in the
browser to handle this, along with a (rare) synchronous
ajax request to run a PHP termination script.
Post by Stuart Dallas
--
Cheers -- Tim
Really - you expect something that was being typed just before closing
to be (magically?) present when you re-open the browser to that page?
I would never expect something like to occur in any kind of computer
application that (most likely) has procedures to be followed to properly
use that page and save that data before closing it. Failure to follow the
rules and an abrupt closure of the page/browser should not retain whatever
I was doing and I can't fault it.
Granted - you are doing this for you appls. but the mere fact that you
have done so surprises me. I would never think to provide that service on
my appls.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Shawn,

Please do not top post to this list.

Cheers
Tim
--
Course View Towers,
Plot 21 Yusuf Lule Road,
Kampala
T +256 (0) 312 314 418
M +256 (0) 752 963 325
www.weberpafrica.com
@TimSchofield2
Blog: http://weberpafrica.blogspot.co.uk/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2014-06-29 05:26:52 UTC
Permalink
Post by Stuart Dallas
Post by Shawn McKenzie
DELETE FROM `php-general` WHERE `from` = 'hadi' OR `from` =
hotmail.com'
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute
when
Post by Shawn McKenzie
Post by Tim Streater
Post by Stuart Dallas
Post by Stuart Dallas
a user closes the browser, so chances are there's a better way to
achieve
Post by Shawn McKenzie
Post by Tim Streater
Post by Stuart Dallas
Post by Stuart Dallas
what he actually wants.
I use that in my app. If the user has been typing into an editing
window,
Post by Shawn McKenzie
Post by Tim Streater
Post by Stuart Dallas
and
then closes the browser window, they will expect that what they typed
will
Post by Shawn McKenzie
Post by Tim Streater
show
up again when they restart the app. I use the onbeforeunload event in
the
Post by Shawn McKenzie
Post by Tim Streater
browser to handle this, along with a (rare) synchronous
ajax request to run a PHP termination script.
Post by Stuart Dallas
--
Cheers -- Tim
Really - you expect something that was being typed just before closing
to be (magically?) present when you re-open the browser to that page?
I would never expect something like to occur in any kind of computer
application that (most likely) has procedures to be followed to properly
use that page and save that data before closing it. Failure to follow
the
Post by Shawn McKenzie
Post by Tim Streater
rules and an abrupt closure of the page/browser should not retain
whatever
Post by Shawn McKenzie
Post by Tim Streater
I was doing and I can't fault it.
Granted - you are doing this for you appls. but the mere fact that you
have done so surprises me. I would never think to provide that service
on
Post by Shawn McKenzie
Post by Tim Streater
my appls.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Shawn,
Please do not top post to this list.
Cheers
Tim
--
Course View Towers,
Plot 21 Yusuf Lule Road,
Kampala
T +256 (0) 312 314 418
M +256 (0) 752 963 325
www.weberpafrica.com
@TimSchofield2
Blog: http://weberpafrica.blogspot.co.uk/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
UPDATE `php-general` SET `status` = 'deleted', `reason`= 'top_posting'
WHERE `from` = 'Shawn' OR `from` = '***@mckenzies.net'

Tim Streater
2014-06-24 21:38:00 UTC
Permalink
Post by Stuart Dallas
Post by Tim Streater
Post by Stuart Dallas
I'm yet to hear of a legitimate reason to want some PHP to execute when
a user closes the browser, so chances are there's a better way to achieve
what he actually wants.
I use that in my app. If the user has been typing into an editing window,
and then closes the browser window, they will expect that what they typed
will show up again when they restart the app. I use the onbeforeunload
event in the browser to handle this, along with a (rare) synchronous ajax
request to run a PHP termination script.
That's certainly a solution to that problem. In the past I've used
onbeforeunload to check if the user has edited anything and display a
confirmation dialog, but never to make a request to the server. I'm
struggling to identify why, but doing that just doesn't sit right with me.
It may be because I've heard that the event is not reliably thrown by all
browsers in all situations as a result of various spammy behaviour by dodgy
sites in the past. That view may well be out of date now. Have you seen any
problems like that?
Well in my case I control which browser is used as I launch it for the user. As this app is mainly for OS X I'm using Safari. Safari behaves thus: if you have an onbeforeunload handler, but exit it without executing a return, the dialog box does not appear (which suits just fine). However I'm now minded to wonder whether that's just a quirk of Safari, and as I'll want to be using Chrome for the Win7 version, I should perhaps test that.

@Jim: I want to protect the user in the same way that something like Word does, although that is based on periodic saves. As it is, only a crash of Safari will stop me saving the actual state - and there's other stuff to save too, such as window position and size (not implemented yet). As I see it, if a text editor like TextWrangler can restore state (including edits) after a restart under pretty much all circumstances, why shouldn't I aspire to do the same. As a user of the app, it's what *I* would expect to happen.
--
Cheers -- Tim
Jim Giner
2014-06-24 21:52:14 UTC
Permalink
Post by Tim Streater
@Jim: I want to protect the user in the same way that something like Word does,
although that is based on periodic saves. As it is, only a crash of
Safari will
stop me saving the actual state - and there's other stuff to save too,
such as
window position and size (not implemented yet). As I see it, if a text
editor
like TextWrangler can restore state (including edits) after a restart under
pretty much all circumstances, why shouldn't I aspire to do the same. As
a user of the app, it's what *I* would expect to happen.
You are too kind to your users.... Of course you'll set a precedent
that will make them expect that behavior from everything.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Robert Williams
2014-06-25 03:29:13 UTC
Permalink
Post by Jim Giner
You are too kind to your users.... Of course you'll set a precedent
that will make them expect that behavior from everything.
In the Mac world, that precedent has already been strongly set by Apple itself. Restart a Mac from the last couple of years, and the restoration of state is so complete that you may not even realize that a restart took place, and mundane, everyday applications (such as text editors) automatically maintain a fully versioned history of even unsaved docs. For a web application with a Mac user base, aspiring to intelligent state management is probably a very smart thing to do, and I doubt many non-Mac users out there would complain about it.

--
Bob Williams

Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any).
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
hadi
2014-06-24 23:51:17 UTC
Permalink
Finally after long research I decide to go with javescrip and ajax.

Here is the code for someone interest into it.

Thanks for your support all.

<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></scr
ipt>



<script type="text/javascript" >

$(window).unload(function() {
$.ajax({
url:"test2.php",
type:"POST",
async:false, // so browser waits till xhr completed
success:function() {
alert("bye!");
}


});


});
</script>


<?php


echo "welcome\n";

?>
Loading...