PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mbleonardo
Forum Newbie
Posts: 3 Joined: Tue Dec 02, 2003 6:23 pm
Post
by mbleonardo » Tue Dec 02, 2003 6:23 pm
Anybody knows as to execute a function php when the user leave the page? (when it presses the X button to close)
In this case, I will like to drop any registry in a database.
Sorry for my bad english
uberpolak
Forum Contributor
Posts: 261 Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar
Post
by uberpolak » Tue Dec 02, 2003 6:35 pm
Can't be done, that's a client-side task, and PHP is server-side.
mbleonardo
Forum Newbie
Posts: 3 Joined: Tue Dec 02, 2003 6:23 pm
Post
by mbleonardo » Tue Dec 02, 2003 6:44 pm
In ASP it gives to make this
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Tue Dec 02, 2003 7:55 pm
you can do this a lot easier with javascript..
something like this would work :
Code: Select all
<script language="JavaScript">
<!--
function onexit()
{
document.location.href = 'mysite.php';
}
//-->
</script>
</head>
<body onUnload="onexit()">
you could throw some function calls, session calls, whatever inside that onexit function.
hope this helps.
mchaggis
Forum Contributor
Posts: 150 Joined: Mon Mar 24, 2003 10:31 am
Location: UK
Post
by mchaggis » Wed Dec 03, 2003 3:21 am
mbleonardo wrote: In ASP it gives to make this
Only really works in IE tho, and I believe that these functions end up using JS at somepoint (could be wrong), it's just hidden from you.
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Wed Dec 03, 2003 3:31 am
infolock wrote: you can do this a lot easier with javascript..
something like this would work :
Code: Select all
<script language="JavaScript">
<!--
function onexit()
{
document.location.href = 'mysite.php';
}
//-->
</script>
</head>
<body onUnload="onexit()">
you could throw some function calls, session calls, whatever inside that onexit function.
hope this helps.
mMm, infolock, wouldn't that only work when a user goes elsewhere in the browser? If he/she closes it, JS won't be able to execute........i think O_o.
-Nay
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Dec 03, 2003 4:35 am
Nay,
I think yyour right, you need to use onBeforeUnload.
This will execute whevener some closes the broswer, goes to another page within your site or clicks a link to another site.
I recently had to do this so that when a user closes the browser window, it automatically logged the user out. The ONLY way to do this is by useing frames.
Mark
mbleonardo
Forum Newbie
Posts: 3 Joined: Tue Dec 02, 2003 6:23 pm
Post
by mbleonardo » Wed Dec 03, 2003 10:14 am
exists the library Php-gtk that I find that allows to make this, looked at:
<?php
dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));
function saindo() { function when leave; }
$Janela = &new GtkWindow();
$Janela->connect('destroy', 'saindo'); //here
Gtk::main();
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Dec 03, 2003 11:07 am
PHP-GTK manual wrote:
This extension will not allow you to display GTK+ applications in a web browser. It is intended for creating standalone GUI applications.