I am storing the users logging into a site in a .txt file .I want to delete their names when they close the browser directly.I am using php code.Is they a way to delete the name ?
-
How are you storing them? What have you tried? Stack is not going to create your website for you. – Dummy Code Jun 21 '13 at 16:50
-
Please Provide your code? – Saleh Jun 21 '13 at 16:50
-
1possible duplicate of [remove information from mysql table when user close his Browser](http://stackoverflow.com/questions/2195581/remove-information-from-mysql-table-when-user-close-his-browser) – gregmac Jun 21 '13 at 16:50
-
2Short answer is : Don't do that. There's a better way to plan your application. – Dany Caissy Jun 21 '13 at 16:53
3 Answers
There's no sure-fire way to tell if the user has closed his or her web browser. Trying to catch such an action w/ JavaScript will undoubtedly lead to bugs. The only thing you can do is delete said usernames after a pre-defined period of inactivity. If the user hasn't carried out any actions within the pre-defined timeframe, assume that they are inactive.

- 19,513
- 7
- 44
- 66
-
how do we know that he is not doing activity when the browser itself is closed? – user2509748 Jun 21 '13 at 17:00
To remove the line of the text file in PHP: PHP Remove line containing string from a text file
To make a request on unload: JavaScript, browsers, window close - send an AJAX request or run a script on window closing
As Wayne said, there's no sure-fire way, but one thing you could do is use JavaScript to check whether the user closed the tab, and then send an AJAX call to a PHP script that deletes the username from the file.

- 2,866
- 4
- 37
- 57
-
1You can use `onbeforeunload` but very few things are allowed, and you certainly need to _finish fast_ or the browser will cut you off. – Halcyon Jun 21 '13 at 16:55
-
1No, because it's likely not going to work and `onbeforeunload` is the wrong approach. What if the user has two open tabs and closes one? – Halcyon Jun 21 '13 at 17:10
-
@Frits van Campen He cannot open two browsers/tabs with same name.I use the same .txt file n check if already exists before a person logs in.I have even this problem of not able to delete the user when he directly closes. – user2509748 Jun 21 '13 at 17:27