![]() |
|
#1
|
|||
|
|||
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
|
|||
|
|||
|
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:
|
|
#3
|
|||
|
|||
|
tubedogg has it right. Since HTTP is a stateless protocol, there is nothing that can be made to automatically happen upon a browser action.
|
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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