GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Jul-2004, 06:01
shwathi shwathi is offline
New Member
 
Join Date: Jul 2004
Posts: 1
shwathi is on a distinguished road

How to delete record on browser close?


Hi,
I want to delete a session record from db through php. Here $uid is a
session variable, I've already set in another page. Can someone help
me... I want something like this :

<?php
session_start(); ?>
<html> <head>
<script language="javascript">
function unset1()
{
<?php
$connection = mysql_connect("hostname","login","pwd");
mysql_select_db("dbname", $connection);
$sql4 = "DELETE FROM Table1 WHERE uid=$uid";
$result4 = mysql_query($sql4, $connection);
mysql_close($connection);
?>
}
</script></head>

<body unload="unset1()"> </body> </html>

Thanks in advance,
Shwathi.
  #2  
Old 09-Aug-2004, 10:44
tubedogg tubedogg is offline
New Member
 
Join Date: Aug 2004
Posts: 11
tubedogg will become famous soon enough
PHP is a server-side language, so your sample code wouldn't work. Just inserting PHP into the page inside a JavaScript function won't make it run. The page would have to be submitted to the server and even then you'd have to have the code somewhere else.

The way most sessions-based programs handle it is to automatically delete sessions after a certain length of time has passed, by deleting them on the page load of a future visitor. To log a specific user out, they would have to initiate the logout procedure somehow - by clicking on a link, submitting a form, etc.

Let's say you give them this link: mypage.php?cmd=logout

Then in your PHP script you'd have this:
PHP Code:

<?
session_start();

if ($_GET['cmd'] == 'logout') {
    $connection = mysql_connect("hostname","login","pwd");
    mysql_select_db("dbname", $connection);
    $sql4 = "DELETE FROM Table1 WHERE uid=$uid";
    $result4 = mysql_query($sql4, $connection);
    mysql_close($connection);
}

?>

Or something like that.
  #3  
Old 30-Aug-2004, 07:12
cs2 cs2 is offline
Member
 
Join Date: May 2003
Location: California
Posts: 107
cs2 will become famous soon enough
tubedogg has it right. Since HTTP is a stateless protocol, there is nothing that can be made to automatically happen upon a browser action.
__________________
The Whole Internet, LLC
Visit our Homepage, -or-
use our online CSS Editor
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why should you switch to the firebird browser? jrobbio Computer Software Forum - Linux 5 22-Nov-2003 15:08
Using browser extensions to enhance web design jrobbio Web Design Forum 0 27-Jul-2003 17:38
select & delete mysql queries skyloon MySQL / PHP Forum 1 22-Jul-2003 13:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.