Log in

View Full Version : onunload too soon.



MrCraig
25-09-2007, 03:19 PM
Ok, Basically im doing something like a 'How Many Guests Online'

And ive got a


<body onUnload="<? unload(); ?>">
</body>


But it seems to do the unload function as soon as i load.

Anyone know whats up


Unload Function Code

<?php
function unload()
{
$ip = $_SERVER['REMOTE_ADDR'];
$sql = mysql_query("delete from onl_online where ip = '$ip'");
}
?>


Thanks in advance.

Tomm
25-09-2007, 03:29 PM
Thats because there is actually nothing in the onunload tag. The PHP is executed on the server thus making the script execute the query as soon at the user requests the page from your server. The onunload tag is designed to be used with Javascript. You could insert some sort of AJAX function in this tag that requests a PHP page from your server that then executes the code you want to execute.

MrCraig
25-09-2007, 03:30 PM
Thats because there is actually nothing in the onunload tag. The PHP is executed on the server thus making the script execute the query as soon at the user requests the page from your server. The onunload tag is designed to be used with Javascript. You could insert some sort of AJAX function in this tag that requests a PHP page from your server that then executes the code you want to execute.

k, thanks :)

QuickScriptz
26-09-2007, 11:25 AM
Ya, you would have to find some kind of way for the php variables to get into another form so that they are usable...

Want to hide these adverts? Register an account for free!