Jump to content


Need to run a PHP script when window closes or changes

  • Please log in to reply
2 replies to this topic

#1 jrcarr

  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationBeautiful Arkansas Ozarks

Posted 22 February 2006 - 03:28 AM

I've gotten pretty good a programming in PHP, however, my Javascript leaves a lot to be desired.

I'm looking for a way to run a small PHP function with a just a mysql_query if someone closes the browser window or leaves the page and navigates to another page. I'm assuming I need to use onunload() in the body tag, but I don't know if I can use it to call a PHP function directly or if I need to create a Javascript function, that calls a php function. If this is possible, could someone show me some basic code to achieve this. Thanks in advance

Jack Carr

#2 ccl

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 09 March 2006 - 12:13 AM

php runs on the server so you can not use a php function in the browser. You have to submit the page if you want to use php.

#3 fooDigi

  • Members
  • PipPipPip
  • Advanced Member
  • 250 posts
  • LocationDuluth, Mn

Posted 10 March 2006 - 09:46 AM

to elaborate on eors comment..

the server parses the php code first, which sends the results to the client, which the clients browser then parses the javascript. but there are a few 'possible' solutions to your problem, depending on your needs.

how about... calling a new window, maybe a popup, that contains the code needed to run? and of course it could close itself, minimizing user interaction.
All your base are belong to us.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users