Jump to content


Photo

run php when closing browser window?


  • Please log in to reply
3 replies to this topic

#1 tomjones

tomjones
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 August 2006 - 01:37 PM

Hi.

I am creating a login component which stores a simple Y/N value in a MySQL database depending on if the login was successful or not. I need to somehow reset this to N when the user closes the browser window. What would be the best way to achieve this with PHP? I can create the sql statement, but how would I go about running a function when the window is closed?

Thank you for your time.

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 01:40 PM

I dont think this is possible, Powecuts, Illegal Shut downs ect

The best way to find out who is online is
add a field into the DB, last_action or something, as DATETIME field
On the top of every page, have a script
If the user is logged in,
Update the table with last action of that date time

Anyone who has action within the last 10 minutes you can assume they are online
Tell me the problem, I will try tell you the solution

#3 tomjones

tomjones
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 August 2006 - 02:01 PM

Thanks for your reply. Would that amount of database calls be a bit resource intensive?

#4 Vikas Jayna

Vikas Jayna
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationNoida, Delhi, India

Posted 04 August 2006 - 04:27 PM

the onbeforeunload javascript event can be used to open a popup window that will call the php script to do the job. However, this does work across all the browsers
Vikas Jayna,
Project Manager - Jeevansathi.com
7 yrs. exp. in LAMP
Certified Mysql DBA
Zend Certified Engineer




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users