Closed Thread Icon

Preserved Topic: Calling a script at browser close (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18519" title="Pages that link to Preserved Topic: Calling a script at browser close (Page 1 of 1)" rel="nofollow" >Preserved Topic: Calling a script at browser close <span class="small">(Page 1 of 1)</span>\

 
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-01-2001 02:52

Just a little background.

I have a PHP script that sets a temp file to use throughout the users browsing session. When the user either leaves the site or closes the browser during the session, I would like to be able to destroy the temp file.

Is there a method in JavaScript to check for the user action of closing the browser, or leaving the site, to call another PHP script to destroy a file (server side file, not on the users machine) without making it noticeable to the user?

Thanks for any and all replies!
~Butcher~

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-01-2001 04:09

hmm not totally but here's a trick I've used before.


there is the body onunload event which can fire a function so you can have a function like this

function sessionkiller() {
mywin = window.open('phpsessionKillerScript.php','whatever','Read Note');
mywin.blur() // More stuff in the note
setTimeout('mywin.close()','2000') // Give the page time to load before killing it
}

NOTE: To make this as seamless as possible I'd make the window something like 100x100 and place it just down and to the left of the top corner of the current browser window. between that and the blur the user will barely ever see the window which will get closed shortly.

Since you are using PHP you may want to check out this tute about handling sessions.
http://www.phpwizard.net/resources/tutorials/session_intro.html

I'd also look into using cookies for this. These can be set to destroy once the user leaves your site and are the usual way for handling this kind of thing


piece





:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-01-2001 04:19

Butcher, if you're using PHP4 sessions there's no need to destroy anything. PHP4 will automatically call "garbage collecting" function that will delete old sessions...

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-01-2001 21:53

Thanks guys

Actually, I'm not using a session at all. I'm creating the temp file on the server.

The temp file hold the results from a database query, and I'm not quite sure how to store it in a session variable, and break it back out and use it again the way I want to.

Also...

I wasn't sure if I should store that much info in a variable that gets transfered from page to page. If this is a stupid notion, please let me know.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-01-2001 22:38

Butcher, you should really use PHP4 sessions to store database result (in order to pass it from one page to another) instead of using temp file...

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-02-2001 00:04

Mr.maX

Even if it's the results of 100 row 6 or 7 column database SELECT?

Here's a snippit of the code I'm writing:

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>$fp = fopen($temp, "w");
while ($row = mysql_fetch_array($result)){
$photo = $row['path'];
$caption = $row['caption'];
$date = $row['date'];
$photographer = $row['photographer'];
$online = $row['online'];
$id = $row['id'];
$csv_file .= "$photo

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-02-2001 00:25

As i see that you're using MySql database, maybe if you try reading more about TEMPORARY tables will help a little.

quote:
Would I store $result ?


no that won't basically work! as mysql will close the connection and free all results...

You may use the session variables to store the whole rows values as this:
<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
$fp = fopen($temp, "w");
$wholeresults = array(); // <<
while ($row = mysql_fetch_array($result))
{
$wholeresults[] = join('

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-02-2001 03:34

Thanks everybody

I saved $result as a session variable and rearranged my code a bit and it seems to work ok.

I was making it out to be harder than it was.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-02-2001 10:42

Butcher, you shouldn't store that many information anywhere. If you want to create output that's separated by pages use "LIMIT" in "SELECT" SQL query. Also, you can filter online/offline images directly in "SELECT" SQL query...

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-02-2001 23:25

This could still be done outside of sessions as well. Off the top of my head you can do this either of two ways

One is have a function that before it writes the files to the temp directory you can delete all files older than say 24 hours and/or write a php script that checks the directory once a day and clears the old temp files that gets run from a cronjob.



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

« BackwardsOnwards »

Show Forum Drop Down Menu