-1

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 ?

3 Answers3

2

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.

Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66
0

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

Community
  • 1
  • 1
Jeroen
  • 821
  • 1
  • 9
  • 16
0

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.

LonelyWebCrawler
  • 2,866
  • 4
  • 37
  • 57
  • 1
    You 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
  • 1
    No, 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