php execute onUnLoad

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pimp
Forum Newbie
Posts: 9
Joined: Sat Nov 06, 2004 10:22 am

php execute onUnLoad

Post by pimp »

hello. i wonder if it's posible to execute a php script when a page unloads. the page can be php or html. the main ideea was to execute it using javascript using <body onUnLoad=..> but i don't know how to do that. please help me if you know any solutions.

thank you
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

php server side, js client side, so your going down the right track.

call a javascript function that uses the location parameter and redirect your page there.

depends a little on what your trying to do.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

You could also make your onUnload code open a new window which executes PHP code, then closes.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lamia
Forum Newbie
Posts: 11
Joined: Sun Jun 19, 2005 2:21 am

Post by lamia »

Sorted! Replaced escape_Data() routine with this one... I've also put comments on lines where I made a mistake

Code: Select all

function escape_data($data)
  {
  
   if (get_magic_quotes_gpc())  //magic quotes is on
   {
    $data = stripslashes($data);
   }  
   else //if (!is_numeric($data))
   {
    $data = mysql_real_escape_string(trim($data));
   }
   
   return $data; //return mysql_real_escape_string(trim($data),$dbconnect);
  
  }
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

lamia wrote:Sorted! Replaced escape_Data() routine with this one... I've also put comments on lines where I made a mistake

Code: Select all

function escape_data($data)
  {
  
   if (get_magic_quotes_gpc())  //magic quotes is on
   {
    $data = stripslashes($data);
   }  
   else //if (!is_numeric($data))
   {
    $data = mysql_real_escape_string(trim($data));
   }
   
   return $data; //return mysql_real_escape_string(trim($data),$dbconnect);
  
  }
huh??

back to the real issue....you're gonna have a tough time getting anthing to work using unload() as almost every pop-up blocker in the world will catch it and kill it...a horrible, but necessary death.
pimp
Forum Newbie
Posts: 9
Joined: Sat Nov 06, 2004 10:22 am

Post by pimp »

i found the alternative: controlling a popup from the parent, which then launches the php page in a iframe when the child closes
Post Reply